Bit late here, but this one just adds some short explanations and links for some edits.
print("Hi. Today we will calculate your age with your shoes size.")
response1 = input("Are you ready ? (1 = yes, 2 = no)")
#Using variables that are only used once is generally not a good idea.
#(Code in question: no = 2, yes = 1)
if response1 == "2":
print("ok")
elif response1 == "1":
# Code I am talking about: five: int = 5
#(There is no need to hint whether a variable in python is an integer or a string). The type hint (five :int) is used when you want others reading your code to understand how it works(like if you are a developer/module publisher).
# ^ see my link at the end for more information on type hints
#Also, "five" was only used once. The purpose of variables is to be reused.
shoes_size = input("Good ! So firstly tell me your shoes size : ")
#The way you convert something's type is by calling int(something).
print("Now, we have to multiply it by 5. It gives " + int(shoes_size)*5)
TL;DR:
Don't use "only-use" variables. For example, if you want to print(1)
, don't
a = 1
print(a)
The simplest way to convert the type of something is by calling int(something)
,str(something)
,float(something)
,etc. not (int)(something)`
Saves you a pair of parentheses, and makes the code simpler.
Finally, multiplying a string by a number repeats it that many times. The full list of interactions is visible at this link, but be warned, it is the docs, so it is pretty technical.
link about type hints