forked from hogeschool/basecamp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtemplate.py
executable file
·74 lines (49 loc) · 1.7 KB
/
template.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
## TEMPLATE
# Start by writting the problem description.
# Inputs
# First, list all of the inputs, then convert it to Python code.
# Processing
# First, explain how will you solve the problem.
# Then, convert it to code.
# Do this section last.
# Outputs
# First, list all of the outputs, then convert it to Python code.
## EXERCISE 1 - RECTANGLE
# Calculate and print the area of a rectangle
# for width and length given by the user.
# Inputs
width_str = input("enter rectangle width: ")
width_int = int(width_str)
length_str = input("enter rectangle length: ")
length_int = int(length_str)
# Processing
area = width_int * length_int
# Outputs
print("The area of rectangle is:", area)
## EXERCISE 2 - PERIMETER
# Calculate and print the area and perimeter of a rectangle
# for width and length given by the user.
# Inputs
width_str = input("enter rectangle width: ")
width_int = int(width_str)
length_str = input("enter rectangle length: ")
length_int = int(length_str)
# Processing
area = width_int * length_int
perimeter = 2*length_int + 2*width_int
# Outputs
print("The area of rectangle is:", area)
print("The perimeter of rectangle is:", perimeter)
## EXERCISE 3 - MIDDLE DIGIT
# Ask user to input three digit number.
# Then, print out the digit in the middle.
# Note: This exercise is intended to be solved by students on their own.
# Only hints are given in comments.
# Replace lines marked by X with actual Python code
# Inputs
# X Ask user to input three digit number (you can call variable N or number)
# Processing
# X Using division and/or remainder and/or modulo extract the middle digit ...
# ... and assign it to variable D or digit (or any other name of your choice)
# Outputs
# X Print digit (D).