Skip to content

Commit 18fa475

Browse files
committed
q1-q8
1 parent 54eed14 commit 18fa475

File tree

8 files changed

+151
-0
lines changed

8 files changed

+151
-0
lines changed

q1.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
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).
3+
# The numbers obtained should be printed in a comma-separated sequence on a single line.
4+
5+
startNumber = 2000
6+
7+
for startNumber in range(startNumber, 3201):
8+
if startNumber % 7 == 0 and startNumber % 5 != 0:
9+
print(startNumber, end=",")

q2.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Write a program which can compute the factorial of a given numbers.
2+
# The results should be printed in a comma-separated sequence on a single line.
3+
# Suppose the following input is supplied to the program:
4+
# 8
5+
# Then, the output should be:
6+
# 40320
7+
8+
# fact = int(input("Enter number: "))
9+
# i = 1
10+
# for i in range(i,fact):
11+
# fact=fact*i
12+
# print(fact)
13+
14+
15+
def fact(x):
16+
if x == 0:
17+
return 1
18+
return x * fact(x - 1)
19+
20+
x=int(input("Enter Number: "))
21+
print (fact(x))

q3.py

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

q4.py

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

q5.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Define a class which has at least two methods:
2+
# getString: to get a string from console input
3+
# printString: to print the string in upper case.
4+
# Also please include simple test function to test the class methods.
5+
6+
class twoMethods:
7+
def __init__(self):
8+
self.Str1= ''
9+
pass
10+
def inString(self):
11+
self.Str1 = input('Enter a String: ')
12+
def outString(self):
13+
print(self.Str1.upper())
14+
obj = twoMethods()
15+
obj.inString()
16+
obj.outString()

q6.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Write a program that calculates and prints the value according to the
2+
# given formula:
3+
# Q = Square root of [(2 * C * D)/H]
4+
# Following are the fixed values of C and H:
5+
# C is 50. H is 30.
6+
# D is the variable whose values should be input to your program in a
7+
# comma-separated sequence.
8+
# Example
9+
# Let us assume the following comma separated input sequence is given
10+
# to the program:
11+
# 100,150,180
12+
# The output of the program should be:
13+
# 18,22,24
14+
15+
import math
16+
C,H = 50,30
17+
Seq = (input("Enter Sequence: "))
18+
numList = Seq.split(',')
19+
i=0
20+
for item in numList:
21+
Seq = int(numList[i])
22+
Q = math.sqrt((2*C*Seq)/H)
23+
numList[i] = int(Q)
24+
i += 1
25+
print(numList)
26+
27+
# Solution
28+
# import math
29+
# c=50
30+
# h=30
31+
# value = []
32+
# items=[x for x in input().split(',')]
33+
# for d in items:
34+
# value.append(str(int(round(math.sqrt(2*c*float(d)/h)))))
35+
36+
# print ((',').join(value))

q7.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Write a program which takes 2 digits, X,Y as input and generates a
2+
# 2-dimensional array. The element value in the i-th row and j-th column of the
3+
# array should be i*j.
4+
# Note: i=0,1.., X-1; j=0,1,¡­Y-1.
5+
# Example
6+
# Suppose the following inputs are given to the program:
7+
# 3,5
8+
# Then, the output of the program should be:
9+
# [[0, 0, 0, 0, 0], [0, 1, 2, 3, 4], [0, 2, 4, 6, 8]]
10+
11+
strInp= input("Enter 2 numbers: ")
12+
13+
rowCol = [int(n) for n in strInp.split(',')]
14+
x = rowCol[0]
15+
y = rowCol[1]
16+
arr2d=[[0 for j in range(y)] for i in range(x)]
17+
for i in range(x):
18+
for j in range(y):
19+
arr2d[i][j]= i*j
20+
print(arr2d)
21+
22+
# input_str = input()
23+
# dimensions=[int(x) for x in input_str.split(',')]
24+
# rowNum=dimensions[0]
25+
# colNum=dimensions[1]
26+
# arr = [[0 for col in range(colNum)] for row in range(rowNum)]
27+
28+
# for row in range(rowNum):
29+
# for col in range(colNum):
30+
# arr[row][col]= row*col
31+
32+
# print (arr)

q8.py

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

0 commit comments

Comments
 (0)