+ 1
Can´t convert str to int, please help
I'm a total beginner and I can not fix this code... name = input("Type your name") print("Hello " + name + "!") age = input("Type your age") if age >= 18: print("Welcome to the site") else: print(You're not allowed into the site)
5 Answers
+ 3
Luiz Peralta
do this
age = int(input ())
Don't write anything in input function otherwise it will append with input value.
+ 2
Take input as int
Example:
x=int(input())
print(type(x)) #integer
y=input()
print(type(y)) #string
by default input() takes inputs as string
+ 2
Thanks a lot both of you. đ
+ 2
Luiz Peralta
As your coding gets more complex, you may wish to change your variable type during the code.
Example:
age = input() # string
age = int(age) # integer
age = str(age) # string
This enables you to keep the name of your variable, but change it to the type that suits your purpose within the code