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

Python Assignment 1

Uploaded by

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

Python Assignment 1

Uploaded by

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

Python Programming Assignment: Module 1

Part - 1: Operators and Variables

1. The following tasks are related to a birthday party. Create a Python program file to do the following
tasks step-by-step:
I. Take input of the following information from the user console and store them in separate
variables:

a) The birthday person's first name


b) The birthday person's last name
c) Age
d) The number of friends invited
e) Cost of each party favor
f) Cost for cake (total cost)
g) pizza (total cost)
h) water (total cost)

II. Suppose, every friend of the birthday person came with his both of his parents. Count the total
number guests in the party.
III. Suppose, in this party there were 10 staffs. Count the total number of persons available in the
party including the birthday person, his/her parents, guests and staffs.
IV. Assume all guests were given 2 slices of cake. Calculate and print the total number of cake
slices needed.
V. Assume each guest ate 3 slices of pizza and each pizza has 8 slices. Calculate and print the
number of pizzas purchased for the party (round up to the nearest whole pizza).
VI. Assume each guest took 1.5 liters of water. Calculate and print the total liters of water needed.
VII. Suppose, party favor was given to all friends of the birthday person. Calculate and print the
total cost of party favors for all friends
VIII. Calculate the total expenses for Cake, pizza, water, party favors. First three are fixed costs as
taken as input from the user.
IX. Calculate the cost per guest rounded to two decimal places.
X. Use an f-string to display:
■ Birthday person's name and age
■ Number of people attending
■ Number of pizzas
■ Liters of drinks
■ Total cost
■ Cost per person
Part - 2: Logical Statements

1. Write a Python program that takes a student's percentage of marks (0-100) as input. If the
percentage of marks is 40 or above, print "Passed" otherwise don't print anything.

2. Write a Python program that takes a student's percentage of marks (0-100) as input. If the
percentage of marks is 40 or above, print "Passed". Otherwise, print "Failed".

3. Write a Python program that takes a student's percentage of marks (0-100) as input. Find and
print the grade based on the percentage of marks obtained by the student. Use following
gradation scheme:

● 90-100: Print "A"


● 80-89: Print "B"
● 70-79: Print "C"
● 60-69: Print "D"
● Below 60: Print "F"

4. Write a Python program that takes a student's percentage of marks (0-100) and attendance
percentage (0-100) as input. If attendance is below 75%, print "Fail due to low attendance"
regardless of grade. If attendance is 75% or higher:
■ Use the previous grading scale (A, B, C, D, F)
■ For grades C and above, add "Good attendance!" to the output
■ For grade D, add "Pass, but please improve attendance"
■ For grade F, add "Fail, attendance satisfactory but grades need improvement"

Part - 3: Strings
Suppose you received the following encoded message:

AGT007XXXmeetXXXatXXXtheXXXoldXXXlighthouseXXXatXXXmidnightXXXbringXXXtheXXXbluep
rintsXXXandXXXwearXXXaXXXredXXXhatXXXcodewordXXXumbrellaXXXoverXXXandXXXout

Write a python program for performing the following tasks on the encoded message

a) Print the length of the message using len().


b) Extract your agent ID from the message. Where the agent ID is always the first 3 characters of
the received message.
c) Remove "noise" from the message. Noise refers to occurrences of "XXX". Hint: use replace()
function
d) Convert the entire message to lowercase characters. Hint: use lower().
e) Extract the key words from the message i.e. splitting the noise removd message into a list of
words. Hint: use split()
f) Print the third and fifth words (if they exist).
g) Ask the user to input a code word. Check if the secret code word is in the message.
h) Transform the message for additional security with the following two operations (i) reverse the
entire message (hint: use slicing [::-1]), (ii) capitalize every other word in the reversed
message.
i) Prepare the decoded message for transmission with the following:

i. Join all the words in the transformed message with "---" (hint: use join()).
ii. Add the agent ID to the start and end of the message.
iii. Print the final decoded message in all caps (hint: use upper()).

j) Create a formatted string using f-strings that includes:

i. Agent ID
ii. Length of original message
iii. First and last words of the decoded message
iv. Whether the code word was found

You might also like