-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprogram.py
73 lines (52 loc) · 1.57 KB
/
program.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
# File: alpha.py
# Author: Simon Chu
# Date: 2/15/17
# Purpose: to print out the capital letter "A".
def main():
print()
print("Program to print out the letter 'A' ")
print("in various sizes. ")
print("You will enter an odd number between 3 and 21 ")
print("Written by Simon Chu. ")
print()
n = input("Enter an odd number between 3 and 21: ")
print()
# for turnin
print()
# determine if the input is a string
try:
n = int(n)
except ValueError:
print("Error: n must be a number, not \"" + n + "\"")
exit()
i = float(n)
# determine if the number is a integer
if i % 1 != 0:
print("Error: Please enter a whole number, not " + str(n))
exit()
size = int(n)
underscoreLine = size // 2 + 1
# determine whether the number entered is in the valid interval
if size < 3:
print("Error: n must be >= 3, not " + str(n))
exit ()
if size > 21:
print("Error: n must be <= 21, not " + str(n))
exit()
if size % 2 == 0:
print("Error: n must be an odd number, not " + str(n))
exit()
else:
print("For n = " + str(n))
print()
print((size - 1) * " " + "^")
blanks = 1
for line in range(2, size + 1):
if line == underscoreLine:
print((size - line) * " " + "/" + blanks * "_" + "\\")
blanks = blanks +2
else:
print((size - line) * " " + "/" + blanks * " " + "\\")
blanks = blanks + 2
print()
main()