-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathDay_04.py
More file actions
157 lines (117 loc) · 2.31 KB
/
Day_04.py
File metadata and controls
157 lines (117 loc) · 2.31 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
#!/usr/bin/env python
# coding: utf-8
# # Question 14
#
# ### **Question:**
#
# > **_Write a program that accepts a sentence and calculate the number of upper case letters and lower case letters._**
#
# > **_Suppose the following input is supplied to the program:_**
#
#
# Hello world!
#
#
# > **_Then, the output should be:_**
#
#
# UPPER CASE 1
#
# LOWER CASE 9
#
#
# ---
#
# ### Hints:
#
# > **_In case of input data being supplied to the question, it should be assumed to be a console input._**
#
# ---
#
#
#
# **Solutions:**
# In[1]:
word = input()
upper, lower = 0, 0
for i in word:
if "a" <= i and i <= "z":
lower += 1
if "A" <= i and i <= "Z":
upper += 1
print("UPPER CASE {0}\nLOWER CASE {1}".format(upper, lower))
# **OR**
# In[2]:
word = input()
upper, lower = 0, 0
for i in word:
lower += i.islower()
upper += i.isupper()
print("UPPER CASE {0}\nLOWER CASE {1}".format(upper, lower))
# **OR**
# In[3]:
word = input()
upper = sum(
1 for i in word if i.isupper()
) # sum function cumulatively sum up 1's if the condition is True
lower = sum(1 for i in word if i.islower())
print("UPPER CASE {0}\nLOWER CASE {1}".format(upper, lower))
# **OR**
# In[4]:
# solution by Amitewu
string = input("Enter the sentense")
upper = 0
lower = 0
for x in string:
if x.isupper() == True:
upper += 1
if x.islower() == True:
lower += 1
print("UPPER CASE: ", upper)
print("LOWER CASE: ", lower)
# ---
#
# # Question 15
#
# ### **Question:**
#
# > **_Write a program that computes the value of a+aa+aaa+aaaa with a given digit as the value of a._**
#
# > **_Suppose the following input is supplied to the program:_**
#
#
# 9
#
#
# > **_Then, the output should be:_**
#
#
# 11106
#
#
# ---
#
# ### Hints:
#
# > **_In case of input data being supplied to the question, it should be assumed to be a console input._**
#
# ---
#
#
#
# **Solutions:**
# In[5]:
a = input()
total, tmp = 0, str() # initialing an integer and empty string
for i in range(4):
tmp += a # concatenating 'a' to 'tmp'
total += int(tmp) # converting string type to integer type
print(total)
# **OR**
#
# ```python
# a = input()
# total = int(a) + int(2*a) + int(3*a) + int(4*a) # N*a=Na, for example a="23", 2*a="2323",3*a="232323"
# print(total)
# ```
# In[ ]: