Workshop Questions
Workshop Questions
OUTPUT:
Enter a number:7
number is odd number
QUESTION 3
n = int(input("enter a number:"))
if(n%7==0):
print("number is divisble by 7")
else:
print("number is not divisble by 7")
OUTPUT:
enter a number:55
number is not divisble by 7
QUESTION 4
number = int(input("enter a number:"))
if(number%5==0):
print("hello")
else:
print("bye")
OUTPUT:
enter a number:32
bye
QUESTION 5
number =int(input("enter a number"))
last_digit = int(str(number)[-1])
print(last_digit)
OUTPUT:
enter a number1234579
9
QUESTION 6
number = nt(input("enter a number"))
last_digit = int(str(number)[-1])
print(last_digit)
if(last_digit%3==0):
print("last digit is divisible three")
else:
print("last digit is not divisible three")
OUTPUT:
enter a number67856
6
last digit is divisible three
QUESTION 7
year = int(input("Enter a year:"))
if(year%4==0& year%400==0):
print(year,"it is a leapyear")
else:
print(year,"it is a not leapyear")
OUTPUT:
Enter a year:2016
2016 it is a leapyear
QUESTION 8
n= int(input("Enter a number"))
if(n%1000==n):
print("it is a three digit number")
else:
QUESTION 9
age = int(input("Enter a age:"))
if(age>=60):
print(age,"is a senior citizen")
else:
print(age,"is not a senior citizen")
OUTPUT:
Enter a age:44
44 is not a senior citizen
QUESTION 10
g = int(input("enter a number:"))
h = int(input("enter a number:"))
if(g<h):
print(g,"is a lowest number")
elif(h<g):
print(h,"is a lowest number")
else:
print("invalid input")
OUTPUT:
enter a number:60
enter a number:56
56 is a lowest number
QUESTION 11
y = int(input("enter a number:"))
s = int(input("enter a number:"))
if(y>s):
print(y,"is a largest number")
elif(s>y):
print(s,"is a largest number")
else:
print("invalid input")
OUTPUT:
enter a number:8888
enter a number:46
8888 is a largest number
QUESTION 12
number = int(input("Enter a number"))
if(number>=1):
print(number," is a positive number")
elif(number<-1):
print(number,"is a negative number")
else:
print("invalid input")
OUTPUT:
Enter a number-11
-11 is a negative number
QUESTION 13
num = int(input("Enter a number"))
if(num%2==0&num%3==0):
print(num,"is divisible by two and three")
else:
print(num,"is not divisible by two and three")
OUTPUT:
Enter a number9
9 is not divisible by two and three
QUESTION 14
num1 = int(input("Enter a number"))
num2 = int(input("Enter a number"))
num3 = int(input("Enter a number"))
if(num1>=num2 & num1>=num2):
print(num1,"is greatest")
elif(num2>=num1 & num2>=num3):
print(num2,"is greatest")
else:
print(num3)
OUTPUT:
Enter a number8
Enter a number9
Enter a number5
9 is greatest
QUESTION 15
unit = int(input("enter a units"))
if(unit<=100):
payamount = unit*0
print(payamount)
elif(unit<=200):
payamount = (100*0)+((unit-100)*5)
print(payamount)
elif(unit>200):
payamount = (100*0)+((200-100)*5)+((unit-200)*10)
print(payamount)
else:
("invalid input")
OUTPUT:
enter a units600
4500
QUESTION 16
mark = int(input("enter a student mark"))
if(mark>90):
print(mark,"a grade")
elif(mark>80 and mark<=90):
print(mark,"b grade")
elif(mark>60 and mark<=80):
print(mark,"c grade")
else:
print("D grade")
OUTPUT:
enter a student mark85
85 b grade
QUESTION 17
price = int(input("Enter a bike price"))
if(price>=1000000):
tax = 1000000*15/100
print(“tax is:”,tax)
elif(price>=50000):
tax = 50000*10/100
print(“tax is:”,ttax)
elif(price<50000):
tax = 50000*5/100
print(“tax is:”,ttax)
else:
print("invalid input")
OUTPUT:
Enter a bike price200000
Tax is :5000.0
QUESTION 18
day = int(input("enter a day in number"))
if(day == 2):
print("monday")
elif(day== 3):
print("tuesday")
elif(day== 4):
print("wednesday")
elif(day == 5):
print("thursday")
elif(day == 6):
print("friday")
elif(day == 7):
print("saturday")
elif(day == 1):
print("sunday")
OUTPUT:
enter a day in number1
Sunday
QUESTION 19
month = int(input("enter a month in number"))
if(month == 1):
print("january")
elif(month== 2):
print("february")
elif(month== 3):
print("march")
elif(month == 5):
print("april")
elif(month == 5):
print("may")
elif(month == 6):
print("june")
elif(month == 7):
print("july")
elif(month == 8):
print("august")
elif(month == 9):
print("september")
elif(month == 10):
print("october")
elif(month == 11):
print("novenber")
elif(month == 12):
print("december")
output:
enter a month in number9
september
QUESTION 20
working_day = int(input("enter a working day"))
absent_day = int(input("enter a absent day"))
attendence = (wday-aday)
if(attendence>=75):
print("eligble to exam")
else:
print("not eligble to exam")
OUTPUT:
enter a working day150
enter a absent day49
eligble to exam
OUPUT:
2
4
6
8
10
12
14
16
18
20
3) Print first 10 odd numbers
for i in range(1, 20, 2):
print(i)
OUTPUT:
1
3
5
7
9
11
13
15
17
19
OUTPUT:
First 10 even numbers in reverse order:
20
18
16
14
12
10
8
6
4
2
First 10 odd numbers in reverse order:
19
17
15
13
11
9
7
5
3
17
9
11
13
15
17
19
OUTPUT:
Enter a number to print its multiplication table: 5
Multiplication table of 5:
5x1=5
5 x 2 = 10
5 x 3 = 15
5 x 4 = 20
5 x 5 = 25
5 x 6 = 30
5 x 7 = 35
5 x 8 = 40
5 x 9 = 45
5 x 10 = 50
OUTPUT:
Enter a number: 236
The product of the digits of 236 is: 36
OUTPUT:
Enter a number to find its factorial: 5
The factorial of 5 is: 120
OUTPUT:
Enter a number to check if it is prime: 3
3 is a prime number.
Enter a number to check if it is prime: 10
10 is not a prime number.
PATTERN PROGRAMS:
1)
*
**
***
****
*****
n=int(input("enter the number of rows:"))
for i in range (1, n+1):
for j in range(i):
print('* ', end="")
print('')
OUTPUT:
*
**
***
****
*****
2)
* * * * *
* * * *
* * *
* *
*
rows = int(input("Enter number of rows: "))
print()
OUPUT:
Enter number of rows: 5
* * * * *
* * * *
* * *
* *
*
3)
*
***
*****
*******
*********
while k!=(2*i-1):
print("* ", end="")
k += 1
k=0
print()
OUTPUT:
Enter number of rows: 5
*
***
*****
*******
*********
4)
1
12
123
1234
12345
for i in range(rows):
for j in range(i+1):
print(j+1, end=" ")
print()
OUTPUT:
Enter number of rows: 5
1
12
123
1234
12345
5)
1
22
333
4444
55555
rows = int (input ("Please enter how many rows you need: "))
for i in range (rows+1):
for j in range (i):
print(i,end = " ")
print ()
OUTPUT:
Please enter how many rows you need: 5
1
22
333
4444
55555