0% found this document useful (0 votes)
9 views

Python Assignment for Ayesha

Uploaded by

flake
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views

Python Assignment for Ayesha

Uploaded by

flake
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 5

Q1: Write a Python program that sums all even numbers in a below

list of integers using a for loop.

data = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]

output should be looks like below

The sum of even numbers is: 30

Q2: Create program that takes the salary and designation of an employee as input
from the user
& then calculates net salary based on some simple rules such as deductions for
taxes
or other factors, depending on the designation.

The program will

Take the employee's salary and designation as input.

Apply different deductions based on the designation


(e.g., higher tax for managers).

Calculate and output the net salary after deductions.

Example Designation Deductions:

Project Manager: 20%


Web Developer: 10%
Intern: 5%

Q3: Create a program that takes an integer input from the user & prints that number
of stars
on the console

The program will:

Take an integer input (e.g., 5) from the user.

Print that number of stars


e.g.,
***** if you typed 5.

Q4: Create a function named it "tax_calculator"


the function should takes 2 parameters.

1.name
2.salary

a. you have to make a logic


if salary is less than 10000
no tax will apply be apply
b. if salary is more than 10000 but less than 25000
tax ratio will be 3.5
c if salary is more than 25000 but less than 50000
tax ratio will be 5.0
d if salary is more than 50000 but less than 100000
tax ratio will be 7.0
e if salary is more than 100000 re more
tax ratio will be 10.0

hint: formula for


tax_deduction = salary X tax ratio / 100
basic_salary = salary - tax_deduction

task is you have to calculate

basic salary
and
tax deduction amount

and show in
f) table should be looks like this

Name Salary tax dedcution Basic Salary


Moosa 50000 4770 45230
Haseeb 75000 3300 71700
Hamaza 8000 0 8000

(USE python table package install it --> pip install PrettyTable)

Q5: Create the program use a lambda function to simulate the process where a
customer
orders a pizza, a waiter provides the pizza, and customer pays for it.

Break the program down as follows:

1.The customer chooses the pizza type and its price.

2.The waiter provides the pizza.

3.The customer pays the money for the pizza.

Use a lambda function to handle the payment and return the net result.

The lambda function give any name will takes 2 arguments:


pizza (the type of pizza)
and price (the price of the pizza).
It should returns a formatted string that includes the pizza type, its price,
and the payment received.

The program prompts the user to input the type of pizza and the price of the pizza.

Result: After the customer orders the pizza,


the lambda function simulates the waiter providing the pizza and taking the
payment,
and then prints a message with the order details.
expected output:

Enter the type of pizza you want to order:


Chiken Fajita

Enter the price of the pizza:


1500 Rs

Pizza: Chiken Fajita,


Price: 1500 Rs
Payment received: 1500 Rs
Order number # 3454354

Q6: Take a input from user by using input()

a) take number between 1 to 5

b) if user entered number between 1 to 5


show success message.
c) if user entered number more than 5 or less then 1 in negative then
show error message.

use python color package


pip install termcolor (from termcolor import colored)
for success color green and red color for error.

Q7: Self study

Learn regular expression from w3schools.com OR leetcode then do following below


task

Create a function which going to take input from user.

1. You need to check value should be user name

2. Number not allowed

3. Special characters not allowed


.
Spaces are allowed between first and second letters of name

5. Alphabets upper case and lower case are allowed

Like
Bilal Hussain

Valid name

Bilal2023

Invalid name
Q8: Define a function which going to take argument a person height in inches and
also its name
and going to return it's height in feet.

Use INPUT function for take user inputs.

E.g.When you run a function Program should ask following below questions

What is your name?

Prompt: Ayesha

What is your height in inches?

Prompt: 65 inches

Show output:
Ayesha you are 5 feet 5 inches tall

Q9: Creating a simple Ludo dice roll program the logic is random number generation.

In Ludo, players roll a dice to determine their moves, and the dice generates a
number
between 1 and 6.
So write a Python program that simulates dice roll and displays a random number

Use Python package random


use while loop & condition
hint:
function name like Dice_ludo:

1.The function uses random.randint(1, 6) to generate a random integer between 1 and


6.
simulating the roll of a dice.

2.The program asks user to press Enter to roll the dice, and then it displays the
result.

3. Play Again: After each roll, the program asks the user if they want to roll
again.
If the user types "y", the game continues; otherwise, it ends with a thank you
message.

Q10: Create a Function for the marksheet inputs

Inputs "Name", "Std no.", like Name : Fahad Sohail - roll: B3456
- All the inputs should not me be empty
- the name should be string, not any other any other data type, roll no should
be number + strings

Subjects - take the inputs of subjects from users


- total = 100

English - 77/100 =
Maths -
Science -
Social studies -
computer -
Urdu -

these subject sholud not be empty & only accepts integer or float

then create a function total_subject_marks (english, urdu.....)


{
return total = english + urdu + ..................;
}
create a function percentage (total,percentage)
{
percentage = total / number of subjects (10)
}

use if elseif to check

if the percantage is greater 85 or less 100


then you got a A+
if the percantage is greater 75 or less 84
then you got a A
if the percantage is greater 65 or less 74
then you got a B+
if the percantage is greater 60 or less 73
then you got a B
if the percantage is greater 55 or less 60
then you got a c
if the percantage is greater 50 or less 54
then you got a D
if the percantage is less than 50
then you got a F

Ouput:
-************** MarkSheet -************

Name: Fahad Sohail


Roll no: R65634

marks
Subjects Marks
English : 90
Urdu: 77

Example: result
Your total marks = 766
You got a 77.6566%
and have a Grade "A"

You might also like