Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 246fa45

Browse files
committed
Day3 coding Practice
1 parent 2b3212b commit 246fa45

File tree

4 files changed

+73
-0
lines changed

4 files changed

+73
-0
lines changed

‎Day3/q10.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Question:
2+
3+
# Write a program that accepts a sequence of whitespace separated words as input and prints the words after removing all duplicate words and sorting them alphanumerically.
4+
5+
# Suppose the following input is supplied to the program:
6+
7+
# hello world and practice makes perfect and hello world again
8+
9+
# Then, the output should be:
10+
11+
# again and hello makes perfect practice world
12+
13+
word = sorted(list(set(input().split()))) # input string splits -> converting into set() to store unique
14+
# element -> converting into list to be able to apply sort
15+
print(" ".join(word))

‎Day3/q11.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Question:
2+
3+
# Write a program which accepts a sequence of comma separated 4 digit binary numbers as its input and then check whether they are divisible by 5 or not. The numbers that are divisible by 5 are to be printed in a comma separated sequence.
4+
5+
# Example:
6+
7+
# 0100,0011,1010,1001
8+
9+
# Then the output should be:
10+
11+
# 1010
12+
13+
# Function to convert Binary number
14+
# to Decimal number
15+
16+
data = input().split(',')
17+
data = list(filter(lambda i:int(i,2)%5==0,data)) # lambda is an operator that helps to write function of one line
18+
print(",".join(data))

‎Day3/q12.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Write a program that accepts a sentence and calculate the number of letters and digits.
2+
# Suppose the following input is supplied to the program:
3+
# hello world! 123
4+
# Then, the output should be:
5+
# LETTERS 10
6+
# DIGITS 3
7+
s = input()
8+
dl = {'digits':0,'letters':0}
9+
for c in s:
10+
if c.isdigit():
11+
dl["digits"]+=1
12+
elif c.isalpha():
13+
dl["letters"]+=1
14+
else:
15+
pass
16+
17+
print("Letters: ",dl['letters'])
18+
print("Digits: ",dl['digits'])

‎Day3/q13.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Question:
2+
# Write a program that accepts a sentence and calculate the number of upper case letters and lower case letters.
3+
# Suppose the following input is supplied to the program:
4+
# Hello world!
5+
# Then, the output should be:
6+
# UPPER CASE 1
7+
# LOWER CASE 9
8+
9+
w = input()
10+
case = {"UPPERCASE":0,"LOWERCASE":0}
11+
for word in w:
12+
if word.isupper():
13+
case["UPPERCASE"]+=1
14+
elif word.islower():
15+
case["LOWERCASE"]+=1
16+
else:
17+
pass
18+
19+
20+
print("Upper Case: ",case["UPPERCASE"])
21+
print("Lower Case: ",case["LOWERCASE"])
22+

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /