Python Forum
Problems with if / else statement
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Problems with if / else statement
#2
money = int(input('amount of money: '))

multiplier = (input('enter t or h for thousands or hundreds: '))

if multiplier == "t":
	print(money*1000)
else:
	print(money*100)
every input,python treat it as a string only so str() was not needed.

money = int(input('amount of money: '))

t = money * 1000
h = money * 100

multiplier =(input('enter t or h for thousands or hundreds: '))

if multiplier =="t":
	print(t)
else:
	print(h)
variable assignment was wrong as python execute code line by line and t and h you recieve from input are string so you have to use "" for using == operator.
Professional Dentist(32years) fell in love with Python during COVID-19 Lockdown.

"Nothing can stop you from learning new things except your own will"

Reply


Messages In This Thread
Problems with if / else statement - by droid206 - Apr-19-2020, 12:44 AM
RE: Problems with if / else statement - by Shahmadhur13 - Apr-19-2020, 01:47 AM
RE: Problems with if / else statement - by droid206 - Apr-19-2020, 05:56 AM
RE: Problems with if / else statement - by buran - Apr-19-2020, 07:17 AM
RE: Problems with if / else statement - by ndc85430 - Apr-19-2020, 07:55 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Having problems using 'or' in a 'if' statement? umut3806 2 2,182 Jul-21-2019, 11:33 PM
Last Post: umut3806
  problems with the If statement or is it the variables being used NickIgoe 2 2,226 Mar-22-2019, 06:34 AM
Last Post: NickIgoe

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020