-
Notifications
You must be signed in to change notification settings - Fork 0
/
Assignment.py
131 lines (100 loc) · 4.7 KB
/
Assignment.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
## Template
#!/usr/bin/env python3
# Name: <Joshuah Marbell>
# Index number: <PS/ITC/14/0067>
print 'Question 1 \n Answer: '
# TODO: Put your codes here ...
#Creates a variable called line
line = ""
#Iterate through a number of range from 1000 to 7000
for numbers in range(1000, 7001):
#Check if numbers is divisible by 7 and not a multiple of 5
if(numbers % 7 == 0) and (numbers % 5 != 0):
#Stores Everything on in line variable with comma-sepated
line += str(numbers) + ", "
#Prints the line variable
print line, '\n'
print 'Question 2\n Answer: '
total = 0
for numbers in range(2000):
if(numbers % 3 == 0) or (numbers % 5 == 0):
total += numbers
print total, '\n'
print 'Question 3\n Answer: '
decimal_value = int(input("Please enter a value: "));
print '{0:b}'.format(int(decimal_value)), '\n'
print 'Question 4\n Answer: '
def EvenFibonacci(n):
num1 = 1
num2 = 2
z = 0
totalSum =0
while(num1<=n):
if(num1%2 ==0):
totalSum = totalSum + num1
#print(sum)
z = num1
num1 = num2
num2 = z + num2
return totalSum
if __name__ == '__main__':
print EvenFibonacci(4000000), '\n'
print 'Question 5a\n Answer: '
my_input = "0123456789"
Zero = ["****** ", "* * ", "* * ", "* * " , "* * " , "* * " , "****** "]
One = ["* ","* ","* ","* ","* ","* ","* "]
Two = ["****** ", " * "," * ", "****** ", "* ","* ", "****** "]
Three = ["****** ", " * "," * ", "****** ", " * "," * ", "****** "]
Four = ["* * ", "* * ","* * " , "****** ", " * "," * "," * "]
Five = ["****** ", "* ","* " , "****** ", " * ", " * ", "****** "]
Six = ["****** ", "* ","* " , "****** ", "* * ", "* * ", "****** "]
Seven = ["****** "," * " , " * ", " * ", " * ", " * ", " * "]
Eight = ["****** ", "* * ", "* * ", "****** ", "* * " , "* * " , "****** "]
Nine = ["****** ", "* * ", "* * ", "****** ", " * " , " * " , "****** "]
Digits = [Two, Three, Four, Five, Six, Seven, Eight, Nine, Zero, One]
# TODO: Print all the digits on the same line
try:
row = 0
while row < 7:
space = ""
column = 0
while column < len(my_input):
# TODO: Put your code after this comment
space += Digits[column][row]
column += 1
# TODO: Print line here and add an incrementer
print space, '\n'
row += 1
except:
# TODO: Handle one suitable error which may occur
print 'Error!! Please go back to the codes!, \n'
print 'Question 5b\n Answer: '
my_input = "0123456789"
Zero = ["****** ", "* * ", "* * ", "* * ", "* * ", "* * ", "* * ", "* * " , "* * " , "* * " , "****** "]
One = ["* ","* ","* ","* ","* ","* ","* ","* ","* ","* ","* "]
Two = ["****** ", " * "," * ", " * "," * ", "****** ","* ","* ","* ","* ", "****** "]
Three = ["****** ", " * "," * "," * "," * ", "****** ", " * "," * "," * "," * ", "****** "]
Four = ["* * ", "* * ","* * " , "* * " ,"* * " , "****** ", " * "," * ", " * "," * "," * "," * "," * "]
Five = ["****** ", "* ","* " ,"* " ,"* " , "****** ", " * ", " * "," * "," * ", "****** "]
Six = ["****** ", "* ","* " ,"* " ,"* " , "****** ", "* * ", "* * ","* * ","* * ", "****** "]
Seven = ["****** "," * " , " * ", " * ", " * ", " * "," * "," * "," * "," * ", " * "]
Eight = ["****** ", "* * ", "* * ","* * ","* * ", "****** ", "* * " , "* * " ,"* * " ,"* * " , "****** "]
Nine = ["****** ", "* * ", "* * ", "* * ","* * ", "****** ", " * " ," * " ," * " , " * " , "****** "]
Digits = [Two, Three, Four, Five, Six, Seven, Eight, Nine, Zero, One]
# TODO: Print all the digits on the same line
try:
row = 0
while row < 11:
line = ""
column = 0
while column < len(my_input):
# TODO: Put your code after this comment
line += Digits[column][row]
column += 1
# TODO: Print line here and add an incrementer
print line, '\n'
row += 1
except:
# TODO: Handle one suitable error which may occur
print 'Error!! Please go back to the codes!, \n'
raw_input('Press enter to end!')