5 easy python programing

  

There are 5 easy python programing questions, please follow the instruction and hints. Thank YouQ1 Calculation
1 Point
Write a function calculation() such that it can accept two variables and calculate the
addition and subtraction of it. And also it must return both addition and subtraction in a single
return call.
For example:
def calculation(a, b):
# Your Code
resi, res2 = calculation (40, 10)
print(res)
the function should produce results 50, 30
res1 = 50, res2 = 30
Please select file(s)
Select file(s)
Submit Answer
Q2 Digits
2 Points
Write a program that asks a user to input a string representation of an integer and a function
digit(string) that takes in the string as a parameter and counts the number of odd digits
and even digits in that positive integer. You should create a main() function that interacts with
both of your digit functions.
Implement two versions of this function:
a. digitl(string) : going over the digits in the string
b. digit2 (string) : first converting to an integer and then using ‘%’ and ‘W’.
Please select file(s)
Select file(s)
Submit Answer
Q3 Leap Year
2 Points
We add a Leap Day on February 29, almost every four years. The leap day is an extra, or
intercalary day and we add it to the shortest month of the year, February.
In the Gregorian calendar three criteria must be taken into account to identify leap years:
The year can be evenly divided by 4, is a leap year, unless:
The year can be evenly divided by 100, it is NOT a leap year, unless:
• The year is also evenly divisible by 400. Then it is a leap year.
This means that in the Gregorian calendar, the years 2000 and 2400 are leap years, while 1800,
1900, 2100, 2200, 2300 and 2500 are NOT leap years.
Write a function, check_leap_year(year), which takes an integer value that represents a year
and checks if the year is leap or not.
A sample execution is shown below:
Please enter a year: 1990
>> False
Please select file(s)
Select file(s)
Q4 Pine Tree
3 Points
Write a program that, prints a ‘pine tree’ consisting of triangles of increasing sizes, filled with a
character (* or ‘t’ or ‘$’ etc). Your program should consist of three functions:
1. A function print_shifted_triangle(n, m, symbol). It prints an n-line triangle, filled with symbol
characters, shifted m spaces from the left margin.
For example, if we call print_shifted_triangle(3, 4, ‘+’), the expected output is:
+
+++
Left
margin
+++++
4 spaces
2. A function print_pine_tree(n, symbol). It prints a sequence of n triangles of increasing sizes (the
smallest triangle is a 2-line triangle), which forms the shape of a pine tree. The triangles are filled with the
symbol character.
For example, if we call print_pine_tree(3, ‘#’), the expected output is:
#
###
JF
###
#
#
IF
IF
#
JF
Left
margin
###
#####
#
#
####
3. A main() function that interacts with the user to read the number of triangles in the tree and the character
filling the tree.
Please select file(s)
Select file(s)

Purchase answer to see full
attachment

Leave a Comment