-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathif_elif_else_notes_starter.py
88 lines (38 loc) · 1.99 KB
/
if_elif_else_notes_starter.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# Unit 2 Notes: Intro to modules; Intro to if-elif-else
# How to use branching logic in Python.
# A) MODULES are files that contain code you can import to use in your own program.
# The random module contains functions related to generating pseudorandom numbers.
# Import like this at the top of your program:
# randint() function:
# Req 2 int arguments & returns random # between those 2 values (inclusive).
# randrange() function:
# Req 1 int argument & returns random # from a range created from int.
# Challenge: Dice Challenge 1
# Create 2 die variables. Simulate rolling each die by generating a
# random number between 1 and 6 and printing it. Can you use 2 diff methods?
# -------------------------------------------------------------
# B)if statement
# Block of code executes if condition is true.
# Challenge: Simple if
# Generate a random number, 1-100, and print "You generated a 2 digit number!"
# if the random number generated is greater than 9.
# -------------------------------------------------------------
# C)if - else
# if block executes if condition is true;
# else block executes if condition is false.
# Challenge: Coin flip
# Create a coin flipping simulator to randomly flip a coin to be heads/tails.
# if heads, print "Heads"; if tails, print "Tails"
# -------------------------------------------------------------
# D)if - elif - else
# if block executes if condition is true;
# elif block executes if condition is true;
# else block executes if condition is false.
# Challenge: Ice Cream Challenge
# Remember our ice cream algorithm? Recreate your own below, e.g.:
# get flavor from user.
# if user wants vanilla, "You get Vanilla"
# elif user wants chocolate, "You get Chocolate"
# elif user wants strawberry, "You get Strawberry"
# else, "Sorry we don't have that flavor. Here's your Pistachio."
input("Press enter to exit.")