Functions Sheet 2 (2)
Functions Sheet 2 (2)
Prepared by
Problem 1:
- Write a python program that reads a number from the user and create
a function called factFun() to calculate a factorial value of a
number then print it.
Problem 2:
- Write a python program to create a function called sumEven() then
compute the sum of all even numbers between 1 and 15 that entered
from user.
Problem 3:
- Write a python program to input from the user two numbers as num1
and num2 to calculate the value of num1num2 with creating a function
called powFun().
Problem 4:
- Write a python program to enter from the user the values of three
angles of triangle then create a function called
testTriangleAngles() to check and print message Total of
three angles is equal to 180 if it true. Otherwise print
message Total of three angles is not equal to 180.
Problem 5:
- Write a python program to create a function called multTable() to
calculate and print the values of multiplication table for any number
that entered from user.
Problem 6:
- Write a python program to create a function called gradeFun() to
input marks of five subjects for a student as programming, discrete,
math, linear and physics then calculate the percentage and print the
grade according to the following: -
o Percentage >= 90% → Grade is A
o Percentage >= 80% → Grade is B
o Percentage >= 70% → Grade is C
o Percentage >= 60% → Grade is D
o Percentage >= 50% → Grade is E
o Percentage < 50% → Grade is F
Problem 7:
- Write a python program to create a function called disTriangle()
to print the following shape: -
*
**
***
****
*****
Problem 8:
- Write a python program to create a function called disTriangle()
to print the following shape: -
*****
****
***
**
*
Problem 9:
- Write a python program to create a function called triangleTop()
to print the following shape: -
*
***
*****
*******
*********
Problem 10:
- Write a python program to create a function called
triangleBase() to print the following shape: -
*********
*******
*****
***
*
Problem 11:
- Write a python program to create a function called funH() to print
the following shape: -
* *
* *
* *
*****
* *
* *
* *
Problem 12:
- Write a python program to create a function called funS() to print
the following shape: -
*****
*
*
*****
*
*
*****
Problem 13:
- Write a python program to create a function called funA() to print
the following shape: -
*****
* *
* *
*****
* *
* *
* *
Problem 14:
- (Function Template Maximum) Write a python program that uses a
function template called maximum to determine the larger of two
arguments. Test the program using integer, character and floating-
point number arguments.
Problem 15:
- (Function Template Minimum) Write a python program that uses a
function template called minimum to determine the smaller of two
arguments. Test the program using integer, character and floating-
point number arguments.
Problem 16:
- (Circle Area) Write a python program that prompts the user for the
radius of a circle, then calls function circleArea to calculate the
area of that circle.
Problem 17:
- (Distance Between Points) Write a function distance that
calculates the distance between two points (x1, y1) and (x2, y2). All
numbers and return values should be of type float.
Problem 18:
- (Guess the Number Game) Write a program that plays the game of
“guess the number’’ as follows: the program chooses the number to
be guessed by selecting an integer at random in the range 1 to 1000.
The program then displays the following:
I have a number between 1 to 1000.
Can you guess my number?
Please type your first guess.
The player then types a first guess. The program responds with one
of the following:
1. Excellent! You guessed the number!
Would you like to play again (y or n)?
2. Too low. Try again.
3. Too high. Try again.
If the player’s guess in correct, your program should loop until the
player finally gets the number right. Your program should keep
telling the player Too low or Too high to help the player “zero
in” on the correct answer.
Problem 19:
- (Quality Points for Numeric Grades) Write a function
qualityPoints that inputs a student’s average and returns 4 if a
student’s average is 90 – 100, 3 if the average is 80 – 89, 2 if the
average is 70 – 79, 1 if the average is 60 – 69 and 0 if the average is
lower than 60.
ــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــ
https://www.facebook.com/BS.OfficialPage
https://www.youtube.com/c/BadrSayed11