-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain2.py
183 lines (115 loc) · 3.05 KB
/
main2.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
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
age = 18
if age >= 18:
print ("You can vote.")
else:
print("You cannot vote yet")
# if condition1:
#if condition2:
#else:
#else
temperature = 28
if temperature > 30:
print("Its a hot day, stay hydrated.")
elif 20 <= temperature <= 30:
print("The weather is pleasant.")
else:
print("Its a cold day")
student_gpa = 4.5
student_score = 75
if student_gpa >= 3.5:
if 50 <= student_score <= 65:
print(f"Student with GPA {student_gpa} and test score of {student_score} may be eligible for a partial scholarship.")
elif student_score > 65:
print(f"Student with GPA {student_gpa} and test score of {student_score} is eligible for a full scholarship.")
else:
print(f"Student with GPA {student_gpa} and test score of {student_score} is not eligible for a scholarship.")
else:
print(f"Student with GPA {student_gpa} and test score of {student_score} is not eligible for a scholarship.")
names = ["Alice", "Bob", "Charlie", "David"]
for name in names:
print(name)
sentence = "Hello, World"
for character in sentence:
if character.isalpha():
print(character)
for number in range(1, 6):
print(number)
numbers = [12, 45 ,6 ,72, 21,8, 94, 57]
#Initialize a variable "maximum" with the first value from the list "numbers".
maximum = numbers[0]
for num in numbers:
if num > maximum:
maximum = num
print("Maximum value in the list is:", maximum)
count = 1
while count <= 5:
print("Iteration", count)
count +=1
numbers = [1,2,3,4,5,6]
target = 4
for number in numbers:
print(number)
if number == target:
print("Target Found!")
break
scores = [68,42,57,78,35,62,50,92]
total = 0
count = 0
for score in scores:
if score < 50:
continue
total += score
count += 1
average = total / count if count > 0 else 0
print("Average score for scores above 50:", average)
while True:
user_input = input("Enter a positive number: ")
if user_input.isnumeric():
number = int(user_input)
if number > 0:
break
print("Invalid Input. Please Try again")
print("You entered a valid positive number:", number)
sum_even = 0
for num in range(1, 11):
if num % 2 == 0:
sum_even += num
print("Sum of even numbers from 1 to 10:", sum_even)
def greet():
print("Hello World")
greet()
def greet_person(name):
print("Hello", name)
greet_person("Alice")
#result = add(3,7)
#print("3+7=", result)
def greet(name):
message = f"Hello, {name}"
print(message)
greet("Alice")
greeting = "Hello"
def greet(name):
message = f"{greeting}, {name}!"
print(message)
greet("Bob")
print(greeting)
greeting = "Hello"
def greet(name):
global message
message = f"{greeting}, {name}!"
print(message)
greet("Doris")
print(message)
message = f"{greeting}, student!"
print(message)
greeting = "Hello"
name = "Plator"
def greet():
global greeting
greeting = "Goodbye"
name = "Alice"
message = f"{greeting}, {name}!"
print(message)
greet()
print(greeting)
print(name)