Created
June 26, 2017 13:35
-
-
Save saliksyed/d25e549e923f850ed33b6125efd7270e to your computer and use it in GitHub Desktop.
This file contains 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
# Python Starter Quiz | |
# Try your best to answer these questions. It’s just an assessment so I can get | |
# a feel for the level of Python skills in the class. No stress and no grade for this :) | |
# Question 1 : | |
# Print out “Coding is awesome :)” | |
print "Coding is awesome :)" | |
# Question 2: | |
# Print the first 50 even numbers greater than 900 | |
nums = [] | |
i = 901 | |
while len(nums) < 50: | |
if i % 2 == 0: | |
nums.append(i) | |
i += 1 | |
for num in nums: | |
print num | |
# Question 3: | |
# Print “The number you have inputted plus 5 is: <their number + 5>”. | |
# We’ve given you code to read in the number | |
mynumber = float(raw_input("Please enter a number:")) | |
print "The number you have inputted is : " + str(mynumber+5) | |
# Question 4: | |
# print a list of 1000 1’s : [1,1,1,1,1,1] … | |
print [1]*1000 | |
# Question 5: | |
# Make a function that given two lists returns the combined list. | |
# e.g : merge([1,2,3], [4,5,6]) … would give you [1,2,3,4,5,6] | |
def merge(a, b): | |
return a + b | |
print([1,2,3], [4,5,6]) | |
# Question 6: | |
# Make a function that takes in dictionary and a value, if that value is in the dictionary | |
# it returns the keys corresponding to the value | |
# e.g : my_dict = { “A”: 7, “B”: 3 , “C”: 7} … find(my_dict, 7) would yield [“A”, “C”] | |
def find(my_dict, value): | |
ret = [] | |
for key in my_dict: | |
if my_dict[key] == value: | |
ret.append(key) | |
return ret | |
print find({ "A": 7, "B": 3 , "C": 7}, 7) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment