-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.py
127 lines (89 loc) · 2.99 KB
/
main.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
# create a function that will read from a csv file and output to console
import csv
def read_csv():
with open('data.csv', 'r') as csv_file:
csv_reader = csv.reader(csv_file)
for line in csv_reader:
print(line)
read_csv()
print("--//--")
# create a function that will read from a csv file and output to console
# how do I run a python script from the command line?
# python main.py
# how do I install python?
# https://www.python.org/downloads/
# how do I install pip?
# https://pip.pypa.io/en/stable/installing/
# write a function that will take 2 numbers and add them together and then divide the result by zero and return the result
def add(num1, num2):
# add two numbers and divide by zero
return (num1 + num2)/1
print(add(1,2))
print("--//--")
# write a function that will take 2 integer paramters and divide them by zero and return the result
# This code divides two numbers and returns the result. If the second number is zero, it will return None and print an error message.
def divide(num1, num2):
try:
return num1/num2
except ZeroDivisionError as err:
print(err)
print(divide(1,0))
print("--//--")
def divide(num1, num2):
try:
return num1/num2
except ZeroDivisionError as err:
print(err)
print(divide(1,0))
print("--//--")
# write a function that will take 2 integer paramters and divide them by zero and return the result
# write a hello world example in python
print("Hello World")
print("--//--")
# create a function to divide two user generated numbers with error handling
def divide():
try:
num1 = int(input("Enter a number: "))
num2 = int(input("Enter another number: "))
print(num1/num2)
except ZeroDivisionError as err:
print(err)
except ValueError as err:
print(err)
divide()
print("--//--")
# create a class to store a list of numbers and return the sum of the list
class SumList:
def __init__(self, list):
self.list = list
def sum(self):
total = 0
for x in self.list:
total += x
return total
def __str__(self):
return f"{self.list} = {self.sum()}"
list = SumList([1,2,3,4,5])
print(list)
# print a johnny bravo hello world using a function that takes one parameter true or false
def johnny_bravo(say_hello):
if say_hello:
print("Hey there, pretty momma!")
else:
print("Hey there, pretty momma!")
johnny_bravo(True)
johnny_bravo(False)
# generate a function or a method that takes input from the console and returns it
def get_input():
return input("Enter something: ")
print(get_input())
# create a function that will take a list of numbers and return the sum of the list
def sum_list(list):
total = 0
for x in list:
total += x
return total
print(sum_list([1,2,3,4,5]))
# create a function that is called Product that will take 2 numbers and return the product of the two numbers
def product(num1, num2):
return num1 * num2