-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpart4.py
More file actions
70 lines (63 loc) · 1.43 KB
/
part4.py
File metadata and controls
70 lines (63 loc) · 1.43 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
# While loop syntax and exercise soln
"""
names =[]
while True:
name = input("Enter student name")
if name == "stop":
break
names.append(name)
i = 0
while i<len(names):
print("Student", i, " =", names[i])
i = i+1
"""
# Loop statements
# While Loops: is used to execute a block of code repeatedly as long as a given condition is true.
i = 1
while i<=4:
print(i)
i = i + 1
# check the following conditions
a = 1
while a < 10:
print(a)
a = a + 2
# use while loop to print all natural numbers between 1 to 100
i = 1
while i <= 100:
print(i)
i = i+1
# calculate the of the sum of all the elements in alist
numbers = [1,2,3,4,5]
sum = 0
i = 0
while i < len(numbers):
sum = sum + numbers[i]
i = i+1
print("Sum =", sum)
""" white a program that accepts the names of n students and
then display their name.
Hint: The total number of student should be provided by the user"""
n = int(input("Enter the total number of students: "))
student_names = []
i = 0
while i < n:
name = input("Enter the name of student " + str(i))
student_names.append(name)
i = i + 1
i = 0
while i<len(student_names):
print("### STUDENT DATABASE")
print(student_names[i])
i = i+1
student_names=[]
while True:
name = input("Student name")
if name == 'x':
break
student_names.append(name)
print("#list of students")
i = 0
while i<len(student_names):
print(student_names[i])
i+=1