Repository navigation
Expand file tree
/
Copy pathPractice.py
More file actions
241 lines (152 loc) · 3.92 KB
/
Copy pathPractice.py
File metadata and controls
241 lines (152 loc) · 3.92 KB
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
# def person(name, age):
# print(name, age)
# person("Harini", 15)
# def func1(*args):
# for i in args:
# print(i)
# func1(20, 40, 60)
# func1(80, 100)
# def calculation(a, b):
# return a + b, a - b
# res = calculation(40, 10)
# print(res)
# def show_employee(name, salary = 9000):
# print("Name:", name, "salary:", salary)
# show_employee("Ben", 12000)
# show_employee("Jessa")
# def factorial(x):
# if x == 0:
# return 1
# else:
# return x * factorial(x - 1)
# x = int(input("Enter a number: "))
# print(factorial(x))
# def prime(n):
# if (n == 1):
# return False
# elif (n == 2):
# return True
# else:
# for x in range(2, n):
# if (n % x == 0):
# return False
# return True
# print(prime(int(input("Enter a number: "))))
# def reverse_str(x):
# return x[::-1]
# y = reverse_str(str(input("Enter what you want to be reversed: ")))
# print(y)
# def sum(x):
# y = 0
# for num in str(x):
# y += int(num)
# return y
# x = 123
# print(sum(x))
# def duplicate(x):
# return list(dict.fromkeys(x))
# list = duplicate(["a", "b", "c", "a", "d", "c"])
# print(list)
# def fibonacci_sequence(n):
# fib_sequence = [0, 1]
# while len(fib_sequence) < n:
# fib_sequence.append(fib_sequence[-1] + fib_sequence[-2])
# return fib_sequence
# terms = 8
# result = fibonacci_sequence(terms)
# print(f"The Fibonacci sequence up to {terms} terms is: {result}")
# def vowel_count(str):
# count = 0
# count2 = 0
# vowel = set("aeiouAEIOU")
# for letter in str:
# if letter in vowel:
# count += 1
# else:
# count2 += 1
# print("Number of vowels:", count)
# print("Number of consonants:", count2)
# x = "Hello World"
# vowel_count(x)
# def person(name, age):
# print(name, age)
# person("Harini", 15)
# def func1(*args):
# for i in args:
# print(i)
# func1(20, 40, 60)
# func1(80, 100)
# def calculation(a, b):
# addition = a + b
# subtraction = a - b
# return addition, subtraction
# res = calculation(40, 10)
# print(res)
# def show_employee(name, salary=9000):
# print("Name:", name, "salary:", salary)
# show_employee("Harini", 12000)
# show_employee("Baskar")
# def outer_function(a, b):
# def sum(a, b):
# return a + b
# add = sum(a, b)
# return add + 5
# result = outer_function(5, 10)
# print(result)
# def sum(num):
# if num:
# return num + sum(num - 1)
# else:
# return 0
# result = sum(10)
# print(result)
# def display_student(name, age):
# print(name, age)
# display_student("Emma", 26)
# show_student = display_student
# show_student("Emma", 26)
# def even(x, y):
# print(list(range(x, y, 2)))
# even(4, 30)
# def largest(item):
# print(item)
# item = [4, 6, 8, 24, 12, 2]
# largest(max(item))
# def divide(x, y):
# try:
# result = x / y
# print(result)
# except ZeroDivisionError:
# print("You can't divide by zero")
# num = 100
# den = 0
# divide(num, den)
def int_input(prompt):
try:
value = int(input(prompt))
return value
except ValueError:
print("Invalid input, input a valid integer.")
n = int_input("Enter an integer: ")
print(n)
def file(filename):
try:
files = open(filename, 'r')
x = file.read()
print(x)
files.close()
except FileNotFoundError:
print("Error: Can't find file name")
file_name = input("Input a file name: ")
file(file_name)
def num(prompt):
while True:
try:
value = float(input(prompt))
return value
except ValueError:
print("Invalid input. Please Input a valid number.")
n1 = num("Enter the first number: ")
n2 = num("Enter the second number: ")
result = n1 * n2
print(result)