equal
deleted
inserted
replaced
73 Larger Questions |
73 Larger Questions |
74 ---------------- |
74 ---------------- |
75 |
75 |
76 .. A minimum of 2 questions here (along with answers) |
76 .. A minimum of 2 questions here (along with answers) |
77 |
77 |
78 1. |
78 1. Given a number, say, n. If it is divisible by 10, print the |
|
79 quotient when divided by 10, otherwise if it is divisible by 5, |
|
80 print the corresponding quotient, otherwise, print the number. |
79 |
81 |
80 2. |
82 |
|
83 Answer:: |
|
84 |
|
85 if n%10==0: |
|
86 print n/10 |
|
87 elif n%5==0: |
|
88 print n/5 |
|
89 else: |
|
90 print n |
|
91 |
|
92 2. Given a number, say, n. Write an if block to multiply n by three |
|
93 and add 1, if it is odd, otherwise halve it. |
|
94 |
|
95 Answer:: |
|
96 |
|
97 if n % 2: |
|
98 n = n*3+1 |
|
99 else: |
|
100 n /= 2 |
|
101 |