-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTask02.py
More file actions
202 lines (182 loc) · 4.81 KB
/
Task02.py
File metadata and controls
202 lines (182 loc) · 4.81 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
# Section 1 of Task 2 in python
print("enter a number to test its divisibility by 3 or 5")
x=eval(input())
if(x%3==0 and x%5==0):
print("Consultadd Python Training")
elif(x%5==0):
print("c")
else:
print("Consultadd")
# Section 2 of Task 2 in python
print("enter 1 for addition")
print("enter 2 for subtraction")
print("enter 3 for division")
print("enter 4 for multiplication")
print("enter 5 for average")
x=eval(input())
if(x==1):
print("enter two numbers for addition one at a time")
first = eval(input())
second = eval(input())
result = first + second
print("final result is: ", result)
if (result < 0):
print("Zsa")
elif(x==2):
print("enter two numbers for subraction one at a time")
first = eval(input())
second = eval(input())
result = first - second
print("final result is: ", result)
if (result < 0):
print("Zsa")
elif(x==3):
print("enter two numbers for division one at a time")
first = eval(input())
second = eval(input())
result = first / second
print("final result is: ", result)
if (result < 0):
print("Zsa")
elif(x==4):
print("enter two numbers for multiplication one at a time")
first = eval(input())
second = eval(input())
result = first * second
print("final result is: ", result)
if (result < 0):
print("Zsa")
elif(x==5):
print("enter two numbers for average one at a time")
first1 = eval(input())
second2 = eval(input())
result = (first1+second2)/2
print("final result is: ", result)
if (result < 0):
print("Zsa")
# Section 3 of Task 2 in python
age = 38
if (age >= 11):
print("You are eligible to see the Football match.")
if (age <= 20 or age >= 60):
print("Ticket price is $12")
else:
print("Ticket price is $20")
else:
print("You are not eligible to buy a ticket.")
# Section 4 of Task 2 in python
#Write a program in Python to break and continue if the following cases occur:
#If a user enters a negative number just break the loop and print “It’s Over”
#If a user enters a positive number just continue in the loop and print “Good Going”
while True:
print("Enter any number")
x=eval(input())
if(x<0):
print("It's Over")
break
print("Good Going")
continue
# Section 5 of Task 2 in python
#Write a program in Python which will find all such numbers which are divisible by 7 but are not a multiple of 5,
#between 2000 and 3200.
x=2000
while x<=3200:
if(x%7==0 and x%5!=0):
print(x)
x+=1
# Section 6 of Task 2 in python
# What is the output of the following code examples?
x=123
for i in x:
print(i)
# Answer TypeError: int object is not iterable
i = 0
while i < 5:
print(i)
i += 1
if i == 3:
break
else:
print("error")
#Answer
#0
#1
#2
count = 0
while True:
print(count)
count += 1
if count >= 5:
Break
#Answer Break is not defined
# Section 7 of Task 2 in python
# Write a program that prints all the numbers from 0 to 6 except 3 and 6.
i=0
while i<7:
print(i)
i+=1
if(i==3 or i==6):
i+=1
continue
# Section 8 of Task 2 in python
# Write a program that accepts a string as an input from the user and calculates the number of digits and letters.
print("please enter any string that may include digits and letters")
str=input()
digits=letters=0
for i in str:
if i.isdigit():
digits+=1
if i.isalpha():
letters+=1
print("The number of digits are {}".format(digits))
print("The number of letters are {}".format(letters))
# Section 9 of Task 2 in python
# Write a program such that it asks users to “guess the lucky number”. If the correct number is guessed the program stops, otherwise it continues forever.
lucky_number = 5
while True:
print("write the lucky number")
x=eval(input())
if x==lucky_number:
break
print("keep guessing")
# Second part of the same question
lucky_number = 5
while True:
print("write the lucky number")
number=eval(input())
if number==lucky_number:
print("you have guessed right")
break
print("Would you like to continue guessing? Enter yes or no")
answer=input()
if(answer=='no'):
break
else:
continue
# Section 10 of Task 2 in Python
lucky_number=5
counter=1
while counter<=5:
print("guess the lucky number")
x=eval(input())
if x==lucky_number:
print("Good guess!")
else:
print("Try again!")
counter+=1
print("Game over!")
# Section 11 of Task 2 in Python
lucky_number=5
counter=1
while counter<=5:
print("guess the lucky number")
x=eval(input())
if x==lucky_number:
print("Good guess!")
break
else:
if counter<5:
print("Try again!")
counter+=1
if counter==6:
print("Sorry but that was not very successful")