Skip to content

Commit 2b3212b

Browse files
committed
Day1 & day2
0 parents  commit 2b3212b

File tree

10 files changed

+167
-0
lines changed

10 files changed

+167
-0
lines changed

Day1/q1.py

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Write a program which will find all such numbers which are divisible by 7 but are not a multiple of 5,
2+
# between 2000 and 3200 (both included).The numbers obtained should be printed in a comma-separated sequence on a single line.
3+
4+
for i in range(2000,3201):
5+
if i%7==0 and i%5!=0:
6+
print(i,end=',')
7+

Day1/q2.py

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Write a program which can compute the factorial of a given
2+
# numbers.The results should be printed in a comma-separated
3+
# sequence on a single line.Suppose the following input is
4+
# supplied to the program: 8 Then, the output should be:40320
5+
6+
def factorial(a):
7+
if a==0:
8+
return 1
9+
return a*factorial(a-1)
10+
11+
number = int(input("Enter the number: "))
12+
print(factorial(number))

Day1/q3.py

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# With a given integral number n, write a program to generate a dictionary that contains (i, i * i) such that is an integral number between 1 and n (both included).
2+
# and then the program should print the dictionary.Suppose the following input is
3+
# supplied to the program: 8
4+
5+
# Then, the output should be: {1: 1, 2: 4, 3: 9, 4: 16, 5: 25, 6: 36, 7: 49, 8: 64}
6+
7+
number = int(input("Enter the number: "))
8+
9+
d = dict()
10+
for i in range(1,number+1):
11+
d[i] = i*i
12+
print(d)

Day2/q4.py

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Write a program which accepts a sequence of comma-separated numbers from console and generate a list and a tuple which contains every number. Suppose the following input is supplied to the program: 34,67,55,33,12,98
2+
3+
# Then, the output should be:
4+
5+
# ['34', '67', '55', '33', '12', '98']
6+
# ('34', '67', '55', '33', '12', '98')
7+
8+
lst = input().split(',')
9+
10+
tpl = tuple(lst)
11+
12+
print(lst)
13+
print(tpl)

Day2/q5.py

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Question:
2+
3+
# Define a class which has at least two methods:
4+
5+
# getString: to get a string from console input
6+
# printString: to print the string in upper case.
7+
# Also please include simple test function to test the class methods.
8+
9+
# Hints:
10+
# Use init method to construct some parameters
11+
12+
class IOstring():
13+
def __init__(self):
14+
pass
15+
def getString(self):
16+
self.s = input()
17+
def printString(self):
18+
print(self.s.upper())
19+
20+
string = IOstring()
21+
string.getString()
22+
string.printString()

Day2/q6.py

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Question:
2+
3+
# Write a program that calculates and prints the value according to the given formula:
4+
5+
# Q = Square root of [(2 * C * D)/H]
6+
7+
# Following are the fixed values of C and H:
8+
9+
# C is 50. H is 30.
10+
11+
# D is the variable whose values should be input to your program in a comma-separated sequence.For example Let us assume the following comma separated input sequence is given to the program:
12+
13+
# 100,150,180
14+
# The output of the program should be:
15+
16+
# 18,22,24
17+
from math import sqrt
18+
C,H=50,30
19+
def calc(a):
20+
return sqrt((2 * C * a)/H)
21+
22+
values = input().split(",")
23+
values = [str(round(calc(int(value)))) for value in values]
24+
print(",".join(values))
25+

Day2/q7.py

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Write a program which takes 2 digits, X,Y as input and generates a 2-dimensional array. The element value in the i-th row and j-th column of the array should be i * j.
2+
3+
# Note: i=0,1.., X-1; j=0,1,¡­Y-1. Suppose the following inputs are given to the program: 3,5
4+
5+
# Then, the output of the program should be:
6+
7+
# [[0, 0, 0, 0, 0], [0, 1, 2, 3, 4], [0, 2, 4, 6, 8]]
8+
9+
10+
11+
12+
x,y = map(int,input().split(','))
13+
lst = []
14+
15+
for i in range(x):
16+
tmp = []
17+
for j in range(y):
18+
tmp.append(i*j)
19+
lst.append(tmp)
20+
21+
print(lst)

Day2/q8.py

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Write a program that accepts a comma separated sequence
2+
# of words as input and prints the words in a comma-separated
3+
# sequence after sorting them alphabetically.
4+
5+
# Suppose the following input is supplied to the program:
6+
7+
# without,hello,bag,world
8+
9+
# Then, the output should be:
10+
11+
# bag,hello,without,world
12+
13+
words = [w for w in input().split(",")]
14+
15+
words.sort()
16+
print(",".join(words))

Day2/q9.py

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Write a program that accepts sequence of lines as input and prints the lines after making all characters in the sentence capitalized.
2+
3+
# Suppose the following input is supplied to the program:
4+
5+
# Hello world
6+
# Practice makes perfect
7+
# Then, the output should be:
8+
9+
# HELLO WORLD
10+
# PRACTICE MAKES PERFECT
11+
12+
lst = []
13+
14+
while True:
15+
x = input()
16+
if len(x)==0:
17+
break;
18+
lst.append(x)
19+
20+
for line in lst:
21+
print(line.upper())
22+

README.md

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Python-programming-exercises
2+
---------------------
3+
## Introduction
4+
5+
***The excersise text contents of this repository was collected from github account of [zhiwehu](https://github.com/zhiwehu/Python-programming-exercises).I collected it to practice and solve all the listed problems with python.As I was learning python in this running timeline ,I hope this 100+ excercise will help me a lot to get my hands free with python.***
6+
7+
***In this repository, I will be updating my regular status and activities of the given problems with my own solution.Also, I will be explaining the code and tell my oppinion about the problem if needed. Main Authors solutions are in python 2 & my solutions will be in python 3***
8+
9+
10+
## 100+ Python challenging programming exercises
11+
### 1. Level description
12+
13+
- **Level 1:** *Beginner means someone who has just gone through an introductory Python course. He can solve some problems with 1 or 2 Python classes or functions. Normally, the answers could directly be found in the textbooks*
14+
15+
- **Level 2:** *Intermediate means someone who has just learned Python, but already has a relatively strong programming background from before. He should be able to solve problems which may involve 3 or 3 Python classes or functions. The answers cannot be directly be found in the textbooks.*
16+
17+
- **Level 3:** *Advanced. He should use Python to solve more complex problem using more rich libraries functions and data structures and algorithms. He is supposed to solve the problem using several Python standard packages and advanced techniques.*

0 commit comments

Comments
 (0)