-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSample questions.py
More file actions
127 lines (96 loc) · 2.58 KB
/
Sample questions.py
File metadata and controls
127 lines (96 loc) · 2.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#Question1
# i=int(input("enter number:"))
# fac=1
# if i<0:
# print("negative factorial doesn't exist")
# elif i==0:
# print("facorial of 0 is 1")
# else:
# for i in range(1,i+1):
# fac*=i
# print("Factorial of ",i,"is",fac)0
#Question2
# num=int(input("enter number:"))
# total=0
# for i in range(0,num+1):
# if i%2==0:
# print(i)
# total+=i
# print("Sum of even number:",total)
#Question 3
# str=input("enter string:")
# if str==str[::-1]:
# print(str,'is palindrome')
# else:
# print(str,'is not palindrome')
#Question 4
# def checkPrime(num):
# if num < 2:
# return 0
# else:
# x = num // 2
# for j in range(2, x + 1):
# if num % j == 0:
# return 0
# return 1
# a=1
# b=100
# for i in range(a, b + 1):
# if checkPrime(i):
# print(i, end=" ")
#Question5
# class Calculator:
# def __init__(self):
# self.result=0
# def add(self,num):
# self.result += num
# def subtract(self,num):
# self.result -= num
# def multiply(self,num):
# self.result *= num
# def divide(self,num):
# if num !=0:
# self.result/=num
# else:
# print("Error:diviion by zero is not allowed.")
# def calculator(self,nums):
# for num in nums:
# if num >0:
# self.add(num)
# elif num<0:
# self.subtract(abs(num))
# def get_result(self):
# return self.result
# c= calculator()
# numbers=[5,-2,3,0,4]
# Calculator.calculator(numbers)
# Calculator.multiply(2)
# Calculator.divide(3)
# final_result=Calculator.get_result()
# print("Final Result:",final_result)
#Question6
# words=['cat','Algorithms','supervised','Mother','Tanzeem']
# specified_length=5
# def filter_words(words_list,length):
# new_list=[]
# for word in words_list:
# if len(word)>length:
# new_list.append(word)
# return new_list
# longer_words=filter_words(words,specified_length)
# print(longer_words)
#Question12
# number=[1,2,3,4,5,9,10,29,15,30]
# min=number[0]
# max=number[0]
# for i in range(len(number)):
# if number[i]>max:
# max=number[i]
# elif number[i]<min:
# min=number[i]
# print("Minimum number:",min)
# print("Maximum number:",max)
#Question17
# celsius= int(input("enter temp in celsius:"))
# farenheit= (celsius*(9/5))+32
# print("the converted value is ",farenheit)