+ 2

if statements

can someone please break this code down for me and simplify it for me? spam = 7 if spam > 5: print("five") if spam > 8: print("eight") im using actual python 3 to practice as I go and idk how im suppose to type this out.

11th Feb 2018, 9:20 PM
Ryan Wontz
Ryan Wontz - avatar
6 Respuestas
+ 1
We have spam that is equal to 7. So in this code, spam is represented by 7. Then, if we look at the if statements, they mean that if a statement is true, it will do what is below it. In this, if spam (which equals 7) is greater than 5, than it will print “five”. If spam is great than 8, it will print “eight”. This code’s outcome will be “five” because spam (7) is a bigger number than 5 while spam(7) is less than 8, it will not come out to “eight” since the statement is false. Hope that helps! More info on if statements: https://www.afterhoursprogramming.com/tutorial/JUMP_LINK__&&__python__&&__JUMP_LINK/if-statement/
11th Feb 2018, 9:26 PM
luciel
luciel - avatar
+ 4
7 is greater than(>) 5 and output iz five and less than 8 so second condition is false
11th Feb 2018, 9:23 PM
Vukan
Vukan - avatar
+ 2
that does help but how exactly do i type it out?
11th Feb 2018, 10:36 PM
Ryan Wontz
Ryan Wontz - avatar
+ 2
Are you typing it out in Python Shell or Sololearn?
11th Feb 2018, 10:42 PM
luciel
luciel - avatar
0
python shell
12th Feb 2018, 2:35 AM
Ryan Wontz
Ryan Wontz - avatar
0
Im actually typing all the things I learn in python with python 3.6 (32 bit) as I go. that way I can get a handle on typing faster.
12th Feb 2018, 2:44 AM
Ryan Wontz
Ryan Wontz - avatar