You need to say:
user = int(user)*3
This makes the value of user the original times by 3. Before, you didn't do anything to the value of the multiplication. You need to save the value in a variable
题
So I'm writing a game for a competition.
Up until this point, the user has entered a number.
if user % 2 == 0 :
print("What you entered is an even number.")
print("")
print("So, according to RULE 1, we must now divide it by 2.")
int(user)/ 2
thing2 = "So, now we're left with " + str(user) + "."
print (thing2)
else :
print("What you entered is an odd number.")
print("")
print("So, according to RULE 1, we must now multiply it by 3, and add 1.")
int(user) * 3
user += 1
thing2 = "So, now we're left with " + str(user) + "."
print (thing2)
.... But the int(user) * 3
part doesn't actually multiply the number by 3, but it does add one.
For the record, I've tried loads of possibilities like just having user * 3
(without the int() thing there) and I'm a beginner at Python.
解决方案
You need to say:
user = int(user)*3
This makes the value of user the original times by 3. Before, you didn't do anything to the value of the multiplication. You need to save the value in a variable
其他提示
You need to save the output of that statement:
user = int(user) * 3
You may want to change user to an integer in the beginning so you don't need to keep doing it, something like:
user = int(user)
int(user) * 3
and int(user)/2
return a value, but this value is not assigned. So you have to do
user = user * 3
and
user = user / 2
As pointed out by jonrsharpe in the comments, the int()
appearing in your code is something more complicated than I'd thought. Since during the equality check user
is already a number, you're either simply doing something unnecessary out of confusion or trying to convert floating point to integer (if I recall correctly, in python 3.x division converts integers to floats by default). If it's the latter, you should do user = int(user / 2)
or better yet, user = user // 2
(again thanks to jonrsharpe).