0

Could we use strings in if-else loop?

Eg : x=str(input("Write true or false")) if x=="true": print("You typed True ") elif x=="false": print ("You typed False") else: print("Error")

24th Jan 2020, 4:44 AM
Ishant Chandna
Ishant Chandna - avatar
3 Antworten
+ 3
Why don't u try? Do that coding and check if it does what u want.
24th Jan 2020, 6:15 AM
Oma Falk
Oma Falk - avatar
+ 1
all empty strings are False and all other strings are True
24th Jan 2020, 5:16 AM
Alice
Alice - avatar
0
Yeah you can use strings in if else statements but in your case the program will print Error if the user enters True instead of true and that applies for False too.The str() method around input is redundant since input stringifies the user input implicitly.I know I went beyond your question but I hope you got a thing or two.
25th Jan 2020, 5:31 PM
John
John - avatar