0% found this document useful (0 votes)
9 views23 pages

Workshop Questions

The document contains a series of Python programming exercises that cover various topics including conditional statements, loops, and functions. Each question includes code snippets, expected outputs, and user inputs for tasks such as checking voter eligibility, calculating factorials, and printing patterns. The exercises are designed to help users practice and understand basic programming concepts.

Uploaded by

rifathsalam123
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views23 pages

Workshop Questions

The document contains a series of Python programming exercises that cover various topics including conditional statements, loops, and functions. Each question includes code snippets, expected outputs, and user inputs for tasks such as checking voter eligibility, calculating factorials, and printing patterns. The exercises are designed to help users practice and understand basic programming concepts.

Uploaded by

rifathsalam123
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 23

QUESTION 1

age = int(input("Enter a voter age:"))


if(age>=18):
print("eligible to vote")
else:
print("not eligible to vote")
OUTPUT:
Enter a voter age:4
not eligible to vote
QUESTION 2
num = int(input("Enter a number:"))
if(num%2==0):
print("number is even number")
else:
print("number is odd number")

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:

print("it is not three digit number")


OUTPUT:
Enter a number3890098
it is not three digit number

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

FOR LOOP PROGRAMS:


1) Print first 10 natural numbers

for i in range(1, 11):


print(i)
OUTPUT:
1
2
3
4
5
6
7
8
9
10

2) Print first 10 even numbers

for i in range(2, 21, 2):


print(i)

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

4) Print first 10 even and odd numbers separately in reverse order


print("First 10 even numbers in reverse order:")
for i in range(20, 1, -2):
print(i)

print("First 10 odd numbers in reverse order:")


for i in range(19, 0, -2):
print(i)

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

5) Write a table of input numbers


number = int(input("Enter a number to print its multiplication table: "))
print(f"Multiplication table of {number}:")
for i in range(1, 11):
print(f"{number} x {i} = {number * i}")

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

6) find the product of digits of given numbers

number = int(input("Enter a number: "))


product = 1
for digit in str(number):
product *= int(digit)

print(f"The product of the digits of {number} is: {product}")

OUTPUT:
Enter a number: 236
The product of the digits of 236 is: 36

7) find the sum of digits of given numbers


number = int(input("Enter a number to find the sum of its digits: "))
sum_of_digits = 0
for digit in str(number):
sum_of_digits += int(digit)
print(f"The sum of the digits of {number} is: {sum_of_digits}")
OUTPUT:
Enter a number to find the sum of its digits: 547
The sum of the digits of 547 is: 16

8) Find the factorial of the given number


number = int(input("Enter a number to find its factorial: "))
factorial = 1
for i in range(1, number + 1):
factorial *= i
print(f"The factorial of {number} is: {factorial}")

OUTPUT:
Enter a number to find its factorial: 5
The factorial of 5 is: 120

9) Check whether the given number is prime or not

number = int(input("Enter a number to check if it is prime: "))


if number > 1:
for i in range(2, int(number**0.5) + 1):
if number % i == 0:
print(f"{number} is not a prime number.")
break
else:
print(f"{number} is a prime number.")
else:
print(f"{number} is not a prime number.")

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: "))

for i in range(rows, 0, -1):


for j in range(0, i):
print("* ", end=" ")

print()

OUPUT:
Enter number of rows: 5
* * * * *
* * * *
* * *
* *
*
3)
*
***
*****
*******
*********

rows = int(input("Enter number of rows: "))


k=0
for i in range(1, rows+1):
for space in range(1, (rows-i)+1):
print(end=" ")

while k!=(2*i-1):
print("* ", end="")
k += 1

k=0
print()
OUTPUT:
Enter number of rows: 5
*
***
*****
*******
*********

4)
1
12
123
1234
12345

rows = int(input("Enter number of rows: "))

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

You might also like