Uploaded by Chumile Kiza

Write a function which can calculate the square value of a number given as an argument

advertisement
Write a function which can calculate the square value of a number given as an argument
Write a function to get the difference between a number and 15, if the number is greater than 15
return double the absolute difference.
Define a function that can receive two integer numbers in string form and compute their sum and
then print it.
Sample output:
printValues("1", "2")
3
If you are given three sticks, you may or may not be able to arrange them in a triangle. For example,
if one of the sticks is 12 cms long and the other two are one cm long, it is clear that you will not be
able to get the short sticks to meet in the middle. For any three lengths, there is a simple test to see
if it is possible to form a triangle: “If any of the three lengths is greater than the sum of the other
two, then you cannot form a triangle. Otherwise, you can” Write a function named is_triangle that
takes three integers as arguments, and that prints either “Yes” or “No,” depending on whether you
can or cannot form a triangle from sticks with the given lengths.
Write a function that prompts the user to input three stick lengths, converts them to integers, and
uses is_triangle to check whether sticks with the given lengths can form a triangle.
Write a function to sum three given integers. However, if two values are equal sulm wil be zero.
Write a function that takes a character (i.e. a string of length 1) and returns True if it is a vowel, False
otherwise.
Assign the value 7 to the variable guess_me and the value 1 to the variable start. Write a while loop
that runs while guess_me is less than 10. Print too low if start is less than guess me. If start equals
guess_me, print 'found it!' and exit the loop. If start is greater than guess_me, print ‘oops’ and exit
the loop. Increment start at the end of the loop.
Code a two-player Rock-Paper-Scissors game. Print out a message of congratulations to the winner.
Rules:
- Rock beats scissors
- Paper beats rock
- Scissors beats paper
Write a program to generate a random number between 1 and 9 (including 1 and 9).
Ask the user to guess the number, then tell them whether they guessed too low, too high, or exactly
right. Count how many attempts it took and inform the user of this.
Hint: To understand how to generate a random number visit the following link and read about
random.randint()
https://docs.python.org/3/library/random.html
Write a function to check if a number provided as an argument is a prime number (A number that
has no divisors
Given the year number from the user. You need to check if this year is a leap year. If it is, print LEAP,
otherwise print COMMON. Write a function to do this.
The rules in the Gregorian calendar are as follows:
- a year is a leap year if its number is exactly divisible by 4 and is not exactly divisible by 100
- a year is always a leap year if its number is exactly divisible by 400
Download