mario - CS50 CDNcdn.cs50.net/2016/fall/walkthroughs/mario/more/python/mario-more.pdf“do-while”...

14
mario

Transcript of mario - CS50 CDNcdn.cs50.net/2016/fall/walkthroughs/mario/more/python/mario-more.pdf“do-while”...

Page 1: mario - CS50 CDNcdn.cs50.net/2016/fall/walkthroughs/mario/more/python/mario-more.pdf“do-while” loop while True:! # prompt user! if condition:! break! executes at least once

mario

Page 2: mario - CS50 CDNcdn.cs50.net/2016/fall/walkthroughs/mario/more/python/mario-more.pdf“do-while” loop while True:! # prompt user! if condition:! break! executes at least once

¨  prompt and validate user input ¨  draw the pyramid

TODO

Page 3: mario - CS50 CDNcdn.cs50.net/2016/fall/walkthroughs/mario/more/python/mario-more.pdf“do-while” loop while True:! # prompt user! if condition:! break! executes at least once

¨  prompt and validate user input ¨  draw the pyramid

TODO

Page 4: mario - CS50 CDNcdn.cs50.net/2016/fall/walkthroughs/mario/more/python/mario-more.pdf“do-while” loop while True:! # prompt user! if condition:! break! executes at least once

¨  get_int!¨  #include <cs50.h> !

¨  get_int!¨  import cs50

C Python

prompt user!

Page 5: mario - CS50 CDNcdn.cs50.net/2016/fall/walkthroughs/mario/more/python/mario-more.pdf“do-while” loop while True:! # prompt user! if condition:! break! executes at least once

do !{ ! // something happens !} !while (condition); !

C Python

validate input!

Page 6: mario - CS50 CDNcdn.cs50.net/2016/fall/walkthroughs/mario/more/python/mario-more.pdf“do-while” loop while True:! # prompt user! if condition:! break! executes at least once

while (condition) !{ ! // something happens !} !

while condition: ! # something happens !!

C Python

validate input!

Page 7: mario - CS50 CDNcdn.cs50.net/2016/fall/walkthroughs/mario/more/python/mario-more.pdf“do-while” loop while True:! # prompt user! if condition:! break! executes at least once

“do-while” loop

while True: ! # prompt user ! if condition: ! break !

executes at least once

Page 8: mario - CS50 CDNcdn.cs50.net/2016/fall/walkthroughs/mario/more/python/mario-more.pdf“do-while” loop while True:! # prompt user! if condition:! break! executes at least once

“do-while” loop

while True: ! # prompt user ! if condition: ! break ! checks

condition

Page 9: mario - CS50 CDNcdn.cs50.net/2016/fall/walkthroughs/mario/more/python/mario-more.pdf“do-while” loop while True:! # prompt user! if condition:! break! executes at least once

!if (bool1 || bool2) !!!if (bool1 && bool2) !

!if bool1 or bool2: !!!if bool1 and bool2: !

C Python

compound conditional expressions!

Page 10: mario - CS50 CDNcdn.cs50.net/2016/fall/walkthroughs/mario/more/python/mario-more.pdf“do-while” loop while True:! # prompt user! if condition:! break! executes at least once

þ  prompt and validate user input ¨  draw the pyramid

TODO

Page 11: mario - CS50 CDNcdn.cs50.net/2016/fall/walkthroughs/mario/more/python/mario-more.pdf“do-while” loop while True:! # prompt user! if condition:! break! executes at least once

draw the pyramid ¨  for each row...

¤ print left pyramid n print spaces n print hashes

¤ print gap n  2 spaces

¤ print right pyramid n print hashes

# # ! ## ## ! ### ### ! #### #### ! ##### ##### ! ###### ###### ! ####### ####### !######## ######## !

Page 12: mario - CS50 CDNcdn.cs50.net/2016/fall/walkthroughs/mario/more/python/mario-more.pdf“do-while” loop while True:! # prompt user! if condition:! break! executes at least once

# print something with a newline !print("hello, world") !!# print something without a newline !print("hello, world", end="") !!# print something 50 times !print("#" * 50) !!# print newline !print() !

print() !

Page 13: mario - CS50 CDNcdn.cs50.net/2016/fall/walkthroughs/mario/more/python/mario-more.pdf“do-while” loop while True:! # prompt user! if condition:! break! executes at least once

þ  prompt and validate user input þ  draw the pyramid

TODO

Page 14: mario - CS50 CDNcdn.cs50.net/2016/fall/walkthroughs/mario/more/python/mario-more.pdf“do-while” loop while True:! # prompt user! if condition:! break! executes at least once

# # ! ## ## ! ### ### ! #### #### ! ##### ##### ! ###### ###### ! ####### ####### !######## ######## !

this was mario