Created
November 8, 2015 22:48
-
-
Save AndyNovo/9c28e632a24693ea29a8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#1) What value does the following expression evalutate to? | |
2 ** 3 ** 2 | |
#2) Rewrite this code to use a for loop instead of a while loop: | |
n = 8 | |
while n >= 1: | |
n -= 3 | |
print(n) | |
#3) What is the type of the following expression: | |
25 + 7 == 40 - 9 | |
#4) What will be printed? | |
a = 7 | |
b = a | |
b = b + 2 | |
a = b - 2 | |
print(a,b) | |
#5) Write a boolean expression that evaluates whether | |
#the variable salary is in the interval (25000, 50000] | |
#6) What will be printed? | |
i = 0 | |
while i < 20: | |
i = i + 3 | |
print(i) | |
#7) Write code which reads the contents of a file named "demo.txt" | |
#8) Write a function that consumes a 5-digit positive integer, num, | |
# and prints the thousands digit. (For instance func(12345) prints 2.) | |
#9) Given a long list of names: ["andy", "sara", "simone", "norb", ...] | |
# Write code that will calculate and print out the total number | |
# of times the letter 'n' appears in the list | |
#10) What will be printed? | |
def rf(n): | |
if n == 3: | |
return 2 | |
return (5 + rf(n-1)) | |
a = rf(6) | |
print(a) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment