PersonsName = input('Enter your name: ')
print('Hello', PersonsName)
AnswerToHowAreYouToday = input('How are you feeling today? Are you doing Good or Bad?')
print('Ok', PersonsName,'So today you are basically feeling', AnswerToHowAreYouToday, '.')
a = "Good"
b = "Bad"
if AnswerToHowAreYouToday: a
print('Good')
else:
print('Bad')
2 Answers
Your if else statement indentation is wrong. Generally four whitespaces are used for indentation and is preferred over tabs. Indentation can be ignored in line continuation. But it's a good idea to always indent.
PersonsName = input('Enter your name: ')
print('Hello', PersonsName)
AnswerToHowAreYouToday = input('How are you feeling today? Are you doing Good or Bad?')
print('Ok', PersonsName,'So today you are basically feeling', AnswerToHowAreYouToday, '.')
a = "Good"
b = "Bad"
if AnswerToHowAreYouToday == a:
print('Good')
else:
print('Bad')
Comments
Your if AnswerToHowAreYouToday: a should be like this if AnswerToHowAreYouToday == a. @Santhos have mentioned it but when your code running your output display like this
Enter your name: Deepak
Hello Deepak
How are you feeling today? Are you doing Good or Bad?Good
Ok Deepak So today you are basically feeling Good .
Good
You can see two Good printed at last. To avoid these issues you can improved your code like this
PersonsName = input('Enter your name: ')
print('Hello', PersonsName)
AnswerToHowAreYouToday = input('How are you feeling today? Are you doing Good or Bad? ')
print('Ok', PersonsName,'So today you are basically feeling ', end = '')
a = "Good"
b = "Bad"
if AnswerToHowAreYouToday == a:
print('Good.')
else:
print('Bad.')
Then Output will be:
Enter your name: Deepak
Hello Deepak
How are you feeling today? Are you doing Good or Bad? Good
Ok Deepak So today you are basically feeling Good.
AnswerToHowAreYouTodayis string, not boolean or 3- you don't compare equality with:, you do it with==. The:comes at the end of theifstatement.AnswerToHowAreYouToday. There is no need ofif elsehere. IfAnswerToHowAreYouTodayis something other than"good"and"bad"you would get no output.