-
Notifications
You must be signed in to change notification settings - Fork 0
/
ch3_challenges.py
86 lines (67 loc) · 1.84 KB
/
ch3_challenges.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
# -*- coding: utf-8 -*-
"""
Created on Tue Sep 19 17:13:41 2017
@author: Mark
"""
# print 3 strings
x = "sup"
y = "hello"
z = x + y
print(x)
print (y)
print (z)
print("this is another way of printing a string")
# 2. Write program that prints a message if a variable is less than 10, and
# different message if greater than or equal to 10.
for i in range(15):
if i < 10:
print(i)
print("this value is less than 10")
else:
print(i)
print("this value is greater than or equal to 10")
# 3. write a program that prints a message if a variable is less than or equal
# to 10, another if the variable is greater than 10 but less than or
# equal to 25, and another if the variable is greater than 25.
for i in range(30):
if i < 10:
print(i)
print("kinda small")
elif (i <= 25):
print(i)
print("in the middle")
else:
print(i)
print("big number...")
#doing the same with a function parse()
def parse(num):
num = int(num)
if num <= 10:
print("kinda small")
elif (num <= 25):
print("in the middle")
else:
print("big number...")
parse(10)
parse(23)
parse(290)
# 4. Create a program that divides two variables and prints the remainder.
x =5
y = 2
rem = x%y
print(rem)
# 5. Create a program that takes two variables, divides them, and prints the quotient
x = 10
y = 3
quo = x//y
print(quo)
# 6. Write a program with a variable 'age' assigned to integer that prints different
# strings depending on what integer age is.
age = 15
if age <= 10:
print("young gun")
elif age <= 20:
print("still got time")
else:
print("done son")
#solutions: https://tinyurl.com/zx7o2v9