-
Notifications
You must be signed in to change notification settings - Fork 0
/
looping2-v2.py
111 lines (89 loc) · 2.65 KB
/
looping2-v2.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
question = input("Which Question are you on: ")
question = eval(question)
if (question == 1):
# Q1
integers = input("How many integers: ")
integers = eval(integers)
integers = integers + 1
#
max = 0
min = 100
evenNums = 0
oddNums = 0
value = 0
for k in range(1, integers):
exec(f'num{k} = 0')
for k in range(1, integers):
value = input("Enter a number: ")
f'num{k} = {int} + r"(" {value} + r")"'
value = int(value)
if (value > max):
max = value
if (value < min):
min = value
if (value % 2 == 0):
evenNums = evenNums + 1
else:
oddNums = oddNums + 1
print("Largest Input:", max)
print("Smallest Input:", min)
print("\n\nNumber of Even inputs:", evenNums)
print("Number of Odd Inputs:", oddNums)
if (question == 2):
number = int(input("Enter a value: "))
digits = 0
digit1 = 0
digit2 = 0
digit3 = 0
digit4 = 0
if (number - 10 <= 0):
digits = 1
elif (number - 100 <= 0):
digits = 2
elif (number - 1000 <= 0):
digits = 3
else:
digits = 4
number = str(number)
if (digits >= 4):
digit1 = int(number[0])
if (digits >= 3):
digit2 = int(number[1])
if (digits >= 2):
digit3 = int(number[2])
if (digits >= 1):
digit4 = int(number[3])
else:
print("Invalid Input")
print(digit1, digit1 + digit2, digit1 + digit2 +
digit3, digit1 + digit2 + digit3 + digit4)
if (question == 3):
string = input("\nEnter String: ")
output = "Uppercase Letters: "
for ch in string:
if ch >= "A" and ch <= "Z":
output = output + str(ch) + " "
print(output)
output = "Second Letter of every word: "
for k in range(len(string)):
if k % 2 == 0:
output = output + string[k] + " "
output = 'All vowels replaced with "_": '
string2 = string
string2 = string2.replace("a", "_")
string2 = string2.replace("e", "_")
string2 = string2.replace("i", "_")
string2 = string2.replace("o", "_")
string2 = string2.replace("u", "_")
print(output + string2)
output = "# of digits in string: "
x = len(string)
print(output + str(x))
output = "The positions of all vowels in string: "
for k in range(0, len(string), 1):
if string[k] == "a" or string[k] == "e" or string[k] == "i" or string[k] == "o" or string[k] == "u":
if k+1 >= len(string):
print(output + str(k + 1))
# print(k + 1, end='\n')
else:
print(k + 1, end='. ')