+ 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)

23rd Dec 2020, 7:02 PM
Luiz Peralta
Luiz Peralta - avatar
5 ответов
+ 3
Luiz Peralta do this age = int(input ()) Don't write anything in input function otherwise it will append with input value.
23rd Dec 2020, 7:03 PM
A͢J
A͢J - avatar
+ 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
23rd Dec 2020, 7:05 PM
Ratnapal Shende
Ratnapal Shende - avatar
+ 2
Thanks a lot both of you. 👍
23rd Dec 2020, 7:09 PM
Luiz Peralta
Luiz Peralta - avatar
+ 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
24th Dec 2020, 12:47 AM
Rik Wittkopp
Rik Wittkopp - avatar