-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
129 lines (106 loc) · 2.16 KB
/
app.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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
print("Hello World")
# Intro to Python
age = 20
price = 19.95
first_name = "Mickey"
is_online = False
# Exercise 1
first_name = "John"
last_name = "Smith"
age = 20
is_new = True
# Receive input
name = input("What is your name? ")
print("Hello " + name)
# Type Conversion
birth_year = input("Enter your birth year: ")
age = 2022 - int(birth_year)
print(age)
#float()
#bool()
#str()
# Exercise 2
first = input("Enter first number: ")
second = input("Enter second number: ")
sum = float(first) + float(second)
print("Sum: " + str(sum))
# Strings
course = "Python for Beginners"
print(course.upper())
print(course)
print(course.find("y"))
print(course.replace("for","4"))
print("Python" in course)
# Arithmetic Operations
print(10/3) #division with float as value
print(10//3) #division with integer as value
print(10%3) #remainder
print(10**3) #exponent
x = 10
x = x + 3
x += 3
# Operator Precedence
x = (10 + 3) * 2
x = 10 + 3 * 2
# Comparison Operators
x = 3 > 2 #produces a boolean value
x = 3 == 2 #equality operator
#>
#>=
#<
#<=
#==
#!=
# Logical Operators
price = 25
print(price > 10 and price < 30)
#or
#price(not price > 10)
# if statements
temperature = 35
if temperature > 30:
print("It's a hot day")
print("Drink plenty of water")
elif temperature > 20:
print("It's a nice day")
elif temperature >10:
print("It's a bit cold")
else:
print("It's cold")
print("Done")
#Exercise 3
weight = input("Weight: ")
unit = input("kg or lbs: ")
if unit.upper() == "k":
weight_in_lbs = float(weight) * 2.205
print("Weight in lbs:" + str(weight_in_lbs))
elif unit.upper() == "l":
weight_in_kg = float(weight) / 2.205
print("Weight in kg:" + str(weight_in_kg))
# While Loops
i = 1
while i <= 10:
print(i * "*")
i = i + 1
# Lists
names = ["John", "Bob", "Mickey", "Sam", "Mary"]
names[0] = "Jon"
print(names[0:3])
# List Methods
numbers = [1,2,3,4,5]
numbers.append(6)
numbers.insert(0, -1)
numbers.remove(3)
print(numbers)
print(1 in numbers)
print(len(numbers))
# for loops
numbers = [1, 2, 3, 4, 5]
for item in numbers:
print(item)
# range function
numbers = range(5, 10, 2)
for number in numbers:
print(number)
# Tubles
numbers = (1, 2, 3)