This question already has answers here:
How do you print superscript in Python?
(13 answers)
Closed 4 years ago.
I'm doing a maths revision program and I want to print out a question with y to the power of x(like xⁿ). I can't find a way to print it out as this form. Has anyone got any ideas?
This is how I want it to be displayed.
One possible option using ANSI escape sequences, it is not possible to control font size:
base = "x"
exponent = "n"
print('\033[1BFormula = %s\033[1A%s\033[1B etcetera'%(exponent, base))
In terminal you get:
# x
#Formula = n etcetera
Related
This question already has answers here:
Given n, take tsum of the digits of n. If that value has more than one digit, continue reducing a single-digit number is produced
(4 answers)
Closed 1 year ago.
I have problem and trying to get next:
new_string = "35" #and this result must be like new_int = 3+5.
How im available to do this? I know the type conversion, but not a clue how i should do this.
As you are new to the python, i suggest you doing it using
int(new_string[0]) # 3
int(new_string[1]) # 5
So now you have 2 integers, you can to whatever you want
This question already has answers here:
Python - Split integer into individual digits (undetermined amount of digits)
(4 answers)
Closed 1 year ago.
I cannot describe clearly because English is not my native language
If I input like this
a = 4252
Then I want to take each number component, it should be like this
a1=4; a2=2; a3=5; a4=2
How to do that in python?
If you know it has a similar question in stackoverflow, give me a link
Convert the integer to a string for easy iterability then get the int value of every character like this: a1,a2,a3,a4 = [int(elem) for elem in str(a)]
This question already has answers here:
Why is exponentiation applied right to left?
(4 answers)
Closed 2 years ago.
print (2**3**2)
Answer is 512.
Why 512 is answer not 64? Because ((2^3)^2) = 64
I want to know the inside math operation of print (2** 3**2)
The order of operations for exponentiation is right-to-left, not-left-to right. So:
2**3**2
is interpretted as:
2**(3**2) = 2**(9) = 512
This question already has answers here:
Python Perfect Square
(3 answers)
Check if a number is a perfect square
(25 answers)
Closed 5 years ago.
I wrote this alternative to finding if a number was a perfect square or no how can I fix this:
n = input ('type n ')
message = ('false')
if n>0 and (math.sqrt(n)).is_integer(): message = ('true')
print (message)
This question already has answers here:
How can I read inputs as numbers?
(10 answers)
Closed 6 years ago.
Tools_List=["Hoe","Pitchfork","Shovel"] #`list`
print(Tools_List)
Tools=input("What tools do you want? ")
print(Tools_List[Tools])
One can only index with one index as a time, wheres your prompt asks for 'Tools' plural. I suggest (with the int correction, and lower-case names)
tools = ["Hoe","Pitchfork","Shovel"]
print(tools)
tool = int(input("What tool do you want? "))
print(tools[tool])