0% found this document useful (0 votes)
5 views2 pages

Python Assignment 3

The document contains two programming assignments in Python. The first assignment is to create a star pattern based on a given number of rows, while the second assignment involves implementing a simple calculator using a switch-case structure with if-elif-else statements. Sample outputs for both assignments are provided to illustrate the expected results.

Uploaded by

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

Python Assignment 3

The document contains two programming assignments in Python. The first assignment is to create a star pattern based on a given number of rows, while the second assignment involves implementing a simple calculator using a switch-case structure with if-elif-else statements. Sample outputs for both assignments are provided to illustrate the expected results.

Uploaded by

Ganesh Kumbhar
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Assignment No - 3

Q1: Write python program to print

Star pattern.

n = 5 for i in range(1, n+1):

for j in range(i):

print("*", end=" ") print()

Output:
*
**
** *
** * *
** * * *

Q2) To write a switch case program in Python using


if-elif-else.
print("----- MENU -----")
print("1. Addition") print("2.
Subtraction") print("3.
Multiplication") print("4.
Division") choice =
int(input("Enter your choice: "))

a = int(input("Enter first
number: ")) b =
int(input("Enter second number:
"))

if choice == 1:
print("Addition =", a + b)
elif choice == 2:
print("Subtraction =", a - b)
elif choice == 3:
print("Multiplication =", a * b)

elif choice==4:
if b != 0:
print("Division =",a / b )
else:
print("Division by zero is not possible")
else:
print("Invalid
choice")

Output
----- MENU -----
1. Addition
2. Subtraction
3. Multiplication
4. Division Enter your choice: 1
Enter first number: 10
Enter second number: 5
Addition = 15

You might also like