Skip to content

Commit 9dd6f83

Browse files
committed
Day4
1 parent 246fa45 commit 9dd6f83

File tree

4 files changed

+74
-0
lines changed

4 files changed

+74
-0
lines changed

Day4/q14.py

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Write a program that computes the value of a+aa+aaa+aaaa with a given digit as the value of a.
2+
# Suppose the following input is supplied to the program:
3+
# 9
4+
# Then, the output should be:
5+
# 11106
6+
7+
8+
a=input()
9+
10+
total=int(a)+int(2*a)+int(3*a)+int(4*a)
11+
print(total)

Day4/q15.py

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Use a list comprehension to square each odd number in a list. The list is input by a sequence of comma-separated numbers. Suppose the following input is supplied to the program:
2+
3+
# 1,2,3,4,5,6,7,8,9
4+
# Then, the output should be:
5+
6+
# 1,3,5,7,9
7+
8+
lst= [iforiininput().split(',') ifint(i) %2]
9+
print(",".join(lst))

Day4/q16.py

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Define a class with a generator which can iterate the numbers, which are divisible by 7, between a
2+
# given range 0 and n.
3+
4+
5+
6+
7+
classTest:
8+
defgenerator(self,n):
9+
return [iforiinrange(n) ifi%7==0] # returns the values as a list if an element is divisible by 7
10+
11+
n=int(input())
12+
num=Test()
13+
lst=num.generator(n)
14+
print(lst)

Day4/q17.py

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# If Give an integer N . Write a program to obtain the sum of the first and last digit of this number.
2+
3+
# Input
4+
# The first line contains an integer T, total number of test cases. Then follow T lines, each line contains an integer N.
5+
6+
# Output
7+
# Display the sum of first and last digit of N.
8+
9+
# Constraints
10+
# 1 ≤ T ≤ 1000
11+
# 1 ≤ N ≤ 1000000
12+
# Example
13+
# Input
14+
# 3
15+
# 1234
16+
# 124894
17+
# 242323
18+
19+
# Output
20+
# 5
21+
# 5
22+
# 5
23+
24+
25+
defLastDigit(a):
26+
returna%10
27+
28+
29+
defFirstDigit(a):
30+
# Remove last digit from number
31+
# till only one digit is left
32+
while(a>=10):
33+
a/=10
34+
returnint(a)
35+
36+
37+
t=int(input())
38+
foriinrange(t):
39+
number=int(input())
40+
print(LastDigit(number)+FirstDigit(number))

0 commit comments

Comments
 (0)
close