-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrough.py
More file actions
168 lines (116 loc) · 3.53 KB
/
rough.py
File metadata and controls
168 lines (116 loc) · 3.53 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
'''
a = "Hello"
b = "world"
print(a+b)
print(a,b)
print(a + " " + b)
age = 36
txt = f"my name is john + {age}"
print(txt)
a = "Hello, world"
print(a[0:4])
print(10<9)
a = 10
b = 20
if a > b:
print(a)
else:
print(b)
x = 20
print(isinstance(x, int))
thislist = ["apple", "banana", "cherry"]
thislist[1:2] = ["blackcurrant", "watermelon"]
print(thislist)
myfamily = {
"child1" : {
"name" : "Emil",
"year" : 2004
},
"child2" : {
"name" : "Tobias",
"year" : 2007
},
"child3" : {
"name" : "Linus",
"year" : 2011
}
}
print(myfamily)
for x, obj in myfamily.items():
print(x)
for y in obj:
print(y + ':', obj[y])
def is_even(number):
# number = int(input())
if number % 2 == 0:
return True
else:
return False
print(is_even(22))
# Write a Python program to print all the numbers from 1 to 20 that are divisible by 3. Use a for loop and an if condition inside it.
def div_three():
for number in range(1,21):
if number % 3 == 0:
print(number)
div_three()
# Write a Python function named count_vowels that takes a string and returns the number of vowels (a, e, i, o, u) in that string.
def count_vowels(text):
vowels = ["a", "e", "i", "o", "u"]
count = 0
for vow in text:
if vow in vowels:
count += 1
return(count)
print(count_vowels("Hello!, world"))
# Write a Python program that takes a list of numbers and returns a new list containing only the unique numbers (no duplicates) in the original order.
def list_of_numbers(nums):
unique_list = []
for unique in nums:
if unique not in unique_list:
unique_list .append(unique)
return unique_list
print(list_of_numbers([1,2,3,4,4,5,6,6,6,7]))
# Write a Python program that manages a simple dictionary of student names and their marks. Implement the following operations as functions:
# Add a student with marks, Update marks of an existing student, Delete a student by name, Display all students and their marks
# You can start with an empty dictionary and call your functions to test.
students = {}
def add_new_student():
name = input("Enter the name : ")
mark = int(input("Enter the mark : "))
students[name] = mark
print(students)
add_new_student()
add_new_student()
def update_marks():
name = input("Enter the name of student to update : ")
new_mark = int(input("Enter the new mark to update : "))
students[name] = new_mark
print(students)
update_marks()
def delete_student():
name = input("enter the student name to delete : ")
students.pop(name)
print(students)
delete_student()
def display_students():
print(students)
display_students()
'''
# Question 1: Write a Python function that takes a list of numbers and returns the sum of all even numbers in the list.
def even_number(nums):
total = 0
for number in nums:
if number % 2 == 0:
total = number + total
return total
print(even_number([1,2,3,4,5,6,7,8,9]))
# Question 2: Write a Python function that takes a string and returns a new string with all vowels removed.
def remove_vowels(name):
name_removed = []
vowels = ["a","e","i","o","u"]
for alpha in name:
if alpha not in vowels:
name_removed.append(alpha)
return "".join(name_removed)
print(remove_vowels("siddarth"))
# Question 3: Write a Python program that takes a list of integers and returns a new list with each number squared (number multiplied by itself).