-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathday#3
69 lines (59 loc) · 1.74 KB
/
day#3
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
#Q11 WAP to input a number and check whether it's prime or not
try:
m = int(input("Enter a number: "))
for num in range(2,11):
if m % num == 0 and num != m:
print(f"{m} is not prime")
break
else:
print(f"{m} is prime")
break
except Exception as e:
print("an error occurred!!!! sorrry brooo", e)
#Q12 WAP to input a number and check whether it's palindrome or not
try:
m = input("Enter a number: ")
#reverse the number
reversed_m = m[::-1]
if m==reversed_m:
print (f"{m} is a palindrome")
else:
print(f"{m} is not a palindrome")
except Exception as e:
print("an error occurred!!!! sorrry brooo", e)
#Q13 WAP to extract digits of a number.
try:
m = input("Enter a number: ")
for i in m:
print(i)
except Exception as e:
print("an error occurred!!!! sorrry brooo", e)
#Q14 WAP to create a function which takes a number as an argument and print it's table
try:
number = int(input("Table of the given number = "))
def print_table(number):
for i in range(1, 11):
solution = number * i
print(f"{number} x {i} = {solution}")
print_table(number)
except Exception as e:
print("an error occurred!!!! sorrry brooo", e)
#Q15 WAP to input a string and print it's reverse
try:
string = str(input("Enter the string = "))
reversed_string = string[::-1]
print(reversed_string)
except Exception as e:
print("an error occurred!!!! sorrry brooo", e)
some extra tips and codes
string = str(input("Enter a string: "))
w = ""
for i in string:
w = i+w
print(w)
string = str(input("enter a string:"))
w =""
length =len(string)
for i in range(length-1,-1,-1):
w = w+string[i]
print(w)