From 18fa475e26be66c50e1a65d427fdcfe0a37857d7 Mon Sep 17 00:00:00 2001 From: "s.kibs" <49878108+s-kibs@users.noreply.github.com> Date: Sun, 24 Dec 2023 15:30:12 +0530 Subject: [PATCH 1/6] q1-q8 --- q1.py | 9 +++++++++ q2.py | 21 +++++++++++++++++++++ q3.py | 13 +++++++++++++ q4.py | 13 +++++++++++++ q5.py | 16 ++++++++++++++++ q6.py | 36 ++++++++++++++++++++++++++++++++++++ q7.py | 32 ++++++++++++++++++++++++++++++++ q8.py | 11 +++++++++++ 8 files changed, 151 insertions(+) create mode 100644 q1.py create mode 100644 q2.py create mode 100644 q3.py create mode 100644 q4.py create mode 100644 q5.py create mode 100644 q6.py create mode 100644 q7.py create mode 100644 q8.py diff --git a/q1.py b/q1.py new file mode 100644 index 00000000..8b7d3398 --- /dev/null +++ b/q1.py @@ -0,0 +1,9 @@ +# Write a program which will find all such numbers which are divisible by 7 but are not a multiple of 5, +# between 2000 and 3200 (both included). +# The numbers obtained should be printed in a comma-separated sequence on a single line. + +startNumber = 2000 + +for startNumber in range(startNumber, 3201): + if startNumber % 7 == 0 and startNumber % 5 != 0: + print(startNumber, end=",") diff --git a/q2.py b/q2.py new file mode 100644 index 00000000..fce41ce7 --- /dev/null +++ b/q2.py @@ -0,0 +1,21 @@ +# Write a program which can compute the factorial of a given numbers. +# The results should be printed in a comma-separated sequence on a single line. +# Suppose the following input is supplied to the program: +# 8 +# Then, the output should be: +# 40320 + +# fact = int(input("Enter number: ")) +# i = 1 +# for i in range(i,fact): +# fact=fact*i +# print(fact) + + +def fact(x): + if x == 0: + return 1 + return x * fact(x - 1) + +x=int(input("Enter Number: ")) +print (fact(x)) diff --git a/q3.py b/q3.py new file mode 100644 index 00000000..01ead148 --- /dev/null +++ b/q3.py @@ -0,0 +1,13 @@ +# 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). +# and then the program should print the dictionary. +# Suppose the following input is supplied to the program: +# 8 +# Then, the output should be: +# {1: 1, 2: 4, 3: 9, 4: 16, 5: 25, 6: 36, 7: 49, 8: 64} + +n = int(input("Enter Number: ")) +numberSquare = dict() +for i in range (1,n+1): + numberSquare[i]= i*i +print(numberSquare) diff --git a/q4.py b/q4.py new file mode 100644 index 00000000..9dc66f13 --- /dev/null +++ b/q4.py @@ -0,0 +1,13 @@ +# 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 +# Then, the output should be: +# ['34', '67', '55', '33', '12', '98'] +# ('34', '67', '55', '33', '12', '98') + +x=input('Enter numbers: ') +numberList = x.split(',') +numberTuple = tuple(numberList) +print(numberList,'\n',numberTuple) \ No newline at end of file diff --git a/q5.py b/q5.py new file mode 100644 index 00000000..560959b1 --- /dev/null +++ b/q5.py @@ -0,0 +1,16 @@ +# Define a class which has at least two methods: +# getString: to get a string from console input +# printString: to print the string in upper case. +# Also please include simple test function to test the class methods. + +class twoMethods: + def __init__(self): + self.Str1= '' + pass + def inString(self): + self.Str1 = input('Enter a String: ') + def outString(self): + print(self.Str1.upper()) +obj = twoMethods() +obj.inString() +obj.outString() \ No newline at end of file diff --git a/q6.py b/q6.py new file mode 100644 index 00000000..29b82ae2 --- /dev/null +++ b/q6.py @@ -0,0 +1,36 @@ +# Write a program that calculates and prints the value according to the +# given formula: +# Q = Square root of [(2 * C * D)/H] +# Following are the fixed values of C and H: +# C is 50. H is 30. +# D is the variable whose values should be input to your program in a +# comma-separated sequence. +# Example +# Let us assume the following comma separated input sequence is given +# to the program: +# 100,150,180 +# The output of the program should be: +# 18,22,24 + +import math +C,H = 50,30 +Seq = (input("Enter Sequence: ")) +numList = Seq.split(',') +i=0 +for item in numList: + Seq = int(numList[i]) + Q = math.sqrt((2*C*Seq)/H) + numList[i] = int(Q) + i += 1 +print(numList) + +# Solution +# import math +# c=50 +# h=30 +# value = [] +# items=[x for x in input().split(',')] +# for d in items: +# value.append(str(int(round(math.sqrt(2*c*float(d)/h))))) + +# print ((',').join(value)) \ No newline at end of file diff --git a/q7.py b/q7.py new file mode 100644 index 00000000..534aed3c --- /dev/null +++ b/q7.py @@ -0,0 +1,32 @@ +# 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. +# Note: i=0,1.., X-1; j=0,1,¡­Y-1. +# Example +# Suppose the following inputs are given to the program: +# 3,5 +# Then, the output of the program should be: +# [[0, 0, 0, 0, 0], [0, 1, 2, 3, 4], [0, 2, 4, 6, 8]] + +strInp= input("Enter 2 numbers: ") + +rowCol = [int(n) for n in strInp.split(',')] +x = rowCol[0] +y = rowCol[1] +arr2d=[[0 for j in range(y)] for i in range(x)] +for i in range(x): + for j in range(y): + arr2d[i][j]= i*j +print(arr2d) + +# input_str = input() +# dimensions=[int(x) for x in input_str.split(',')] +# rowNum=dimensions[0] +# colNum=dimensions[1] +# arr = [[0 for col in range(colNum)] for row in range(rowNum)] + +# for row in range(rowNum): +# for col in range(colNum): +# arr[row][col]= row*col + +# print (arr) \ No newline at end of file diff --git a/q8.py b/q8.py new file mode 100644 index 00000000..62d0c8ac --- /dev/null +++ b/q8.py @@ -0,0 +1,11 @@ +# Write a program that accepts a comma separated sequence of words as input and +# prints the words in a comma-separated sequence after sorting them +# alphabetically. +# Suppose the following input is supplied to the program: +# without,hello,bag,world +# Then, the output should be: +# bag,hello,without,world +inp = input("Enter words: ") +words = [n for n in inp.split(',') ] +words.sort() +print(words) From bd81ef6a15f6acf71d07ceeb1a627c996cbb7c99 Mon Sep 17 00:00:00 2001 From: "s.kibs" <49878108+s-kibs@users.noreply.github.com> Date: Sun, 24 Dec 2023 16:04:34 +0530 Subject: [PATCH 2/6] 19.py --- q9.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 q9.py diff --git a/q9.py b/q9.py new file mode 100644 index 00000000..2b4fd35d --- /dev/null +++ b/q9.py @@ -0,0 +1,18 @@ +# Write a program that accepts sequence of lines as input and prints the lines +# after making all characters in the sentence capitalized. +# Suppose the following input is supplied to the program: +# Hello world +# Practice makes perfect +# Then, the output should be: +# HELLO WORLD +# PRACTICE MAKES PERFECT + +strLines= [] + +while True: + userInput = input() + if userInput == '': + break + else: + strLines.append(userInput.upper() + '\n') +print(''.join(strLines)) \ No newline at end of file From fbca3003dcc6208d93361011c033f12276365e52 Mon Sep 17 00:00:00 2001 From: "s.kibs" <49878108+s-kibs@users.noreply.github.com> Date: Sun, 24 Dec 2023 16:37:16 +0530 Subject: [PATCH 3/6] q10 --- q10.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 q10.py diff --git a/q10.py b/q10.py new file mode 100644 index 00000000..1b0e3416 --- /dev/null +++ b/q10.py @@ -0,0 +1,15 @@ +# 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. +# Suppose the following input is supplied to the program: +# hello world and practice makes perfect and hello world again +# Then, the output should be: +# again and hello makes perfect practice world + +rawInp = (input("Enter Input: ")) +newList = [n for n in rawInp.split(' ')] +tempList = [] +[tempList.append(i) for i in newList if i not in tempList] +tempList.sort() +print(' '.join(tempList)) + From b585873898803f176e2d34a570ff85fff3f5a9e5 Mon Sep 17 00:00:00 2001 From: "s.kibs" <49878108+s-kibs@users.noreply.github.com> Date: Mon, 25 Dec 2023 17:05:22 +0530 Subject: [PATCH 4/6] q6 q11 --- q11.py | 18 ++++++++++++++++++ q6.py | 2 +- 2 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 q11.py diff --git a/q11.py b/q11.py new file mode 100644 index 00000000..2fabd0ed --- /dev/null +++ b/q11.py @@ -0,0 +1,18 @@ +# 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. +# Example: +# 0100,0011,1010,1001 +# Then the output should be: +# 1010 +# Notes: Assume the data is input by console. +baseStr = input('Enter binary no.: ') +ans=[] +numSeq = [int(i,2) for i in baseStr.split(',')] + +for i in numSeq: + if i%5==0: + ans.append(bin(i).replace('0b','')) + +print(*ans, sep=',') \ No newline at end of file diff --git a/q6.py b/q6.py index 29b82ae2..2517243a 100644 --- a/q6.py +++ b/q6.py @@ -22,7 +22,7 @@ Q = math.sqrt((2*C*Seq)/H) numList[i] = int(Q) i += 1 -print(numList) +print(*numList, sep=',') # Solution # import math From f0217eea0206ca007fc00ec53cea97b843e94b88 Mon Sep 17 00:00:00 2001 From: "s.kibs" <49878108+s-kibs@users.noreply.github.com> Date: Fri, 5 Jan 2024 16:17:53 +0530 Subject: [PATCH 5/6] q12 --- q12.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 q12.py diff --git a/q12.py b/q12.py new file mode 100644 index 00000000..6230aac1 --- /dev/null +++ b/q12.py @@ -0,0 +1,12 @@ +# Write a program, which will find all such numbers between 1000 and +# 3000 (both included) such that each digit of the number is an even +# number.The numbers obtained should be printed in a comma-separated +# sequence on a single line. + + +numList = [] +for i in range(1000,3001): + num=str(i) + if (int(num[0])%2==0) and (int(num[1])%2==0) and (int(num[2])%2==0) and (int(num[3])%2==0): + numList.append(num) +print(','.join(numList)) From 550144f2379a9b3000d7da6f25f7da8d15f7f555 Mon Sep 17 00:00:00 2001 From: "s.kibs" <49878108+s-kibs@users.noreply.github.com> Date: Thu, 11 Jan 2024 12:05:06 +0530 Subject: [PATCH 6/6] q13.py --- q13.py | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 q13.py diff --git a/q13.py b/q13.py new file mode 100644 index 00000000..07cf64a3 --- /dev/null +++ b/q13.py @@ -0,0 +1,32 @@ +# Write a program that accepts a sentence and calculate the number of +# letters and digits. Suppose the following input is supplied to the +# program: +# hello world! 123 +# Then, the output should be: +# LETTERS 10 +# DIGITS 3 + +# using variables +s = input("Enter input: ") +countNumber = 0 +countLetter = 0 +for i in s: + if i.isdigit() : + countNumber = countNumber + 1 + elif i.isalpha(): + countLetter = countLetter + 1 +print('LETTERS' , countLetter) +print('DIGITS', countNumber) + +# using dictionary +# s = input() +# d={"DIGITS":0, "LETTERS":0} +# for c in s: +# if c.isdigit(): +# d["DIGITS"]+=1 +# elif c.isalpha(): +# d["LETTERS"]+=1 +# else: +# pass +# print ("LETTERS", d["LETTERS"]) +# print ("DIGITS", d["DIGITS"]) \ No newline at end of file