0% found this document useful (0 votes)
6 views3 pages

Worksheet 1

Uploaded by

uskanovjavohir9
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)
6 views3 pages

Worksheet 1

Uploaded by

uskanovjavohir9
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/ 3

No Python Exercises

1 Write a program that allows a user to input their first name, their last name and
age. Store the results into variables.

Based on the information given, print out a proper greeting message.


2 Write a program that allows a user to enter 2 numbers. Your program should
calculate the sum and products of the numbers entered.
3 Write a program that will allow a user to enter a floating point number. Then,
convert the number to an integer.
4 Write a program that asks whether a user is a vegetarian (“Y” for yes and “N” for
no). If the user is a vegetarian, print out a message saying “Your vegetarian meal
is ready”. Otherwise, print out a message saying “Your non-vegetarian meal is
ready”.
5 Write an iterative statement (for loop or while loop) to print out all the odd
numbers from 0 – 30.
6 Write a program that prompts a user to key in a number repeatedly until he/she
enters a negative number (hint: use a while loop).
7 Write a program that prompts a user to enter a number and store it into a
variable called “lucky number”. Then, prompt the user again to guess what is the
previously input number. If the user is correct, the program congratulates he/she
and terminate. If not, the program will ask the user to try again.
8 Write a program that prompts the user to enter his/her name. After that, print
out the following information about the name:

- Length of the name


- First two characters of the name
- Uppercase of the name
- Lowercase of the name
9 Write a program that prompts the user to enter a number. Your program should
display the following information about the number:

- Whether it is an even or odd number


- The remainder of that number when divided by 3
- Power of three of the number
10 Write a program that:

Allows a user to input their Physics test score


Allows a user to input their Biology test score

Outputs the message "Well done! You have passed both tests" if both test scores
are 60 or greater.

Outputs the message You need to try again with the Physics test." if the Physics
test score is less than 75, but the Biology test score is 75 or greater

Outputs the message "You need to try again with the Biology test." if the Biology
test score is less than 75, but the Physics test score is 75 or greater
Outputs the message "You need to try again with both tests" if both test scores
are less than 75

You must use a nested IF statement and Boolean operator in your program.
11 Create an iterative statement that prints the following:

1a
1b
1c
1d
2a
2b
2c
2d
3a
3b
3c
3d

Hint: You will need to use a nested loop. You will also need to use an array.

12 Write a function that tells user whether a function has two solutions, one
solution or no solution – discriminant problem in Maths:

- Takes a parameter a
- Takes a parameter b
- Takes a parameter c

Use the formula Discriminant = b 2 − 4 ac .

Note: If the discriminant is > 0, then the function has two solutions, If
discriminant = 0, then the function has one solution. If discriminant < 0, then the
function has one solution.

Your program should print out the result.

13 Modify your program in Q12 to make the determinant function returns the
determinant. Your function should return the determinant value and it should be
stored into another variable d.

14 Initialise a list that has value from 1 to 10. Initialise another array with 10 “0”.
Using the first list you created, populate the second list like this:

[3,4,5,6,7,8,9,10,11,12], in which each element in the first list has been


incremented by 2.
15 The following tables contains data from a class’s academic result:

Student/Subj Math Science English History


A 33 45 14 41
B 55 90 44 57
C 45 35 67 88

Represent the following data in Python using a list of lists. Write a program that
finds out the top score for each subject and the student with highest average
marks.

You might also like