In: Computer Science
Homework 1 Python basics and flow control Given August 26th – Due September 8th In this assignment you have to develop a security program. Inside a while loop you will ask several security questions. Be creative! When all of them are answered correctly a piece of secret information will be printed and the program will be finished. In your program: - use at least 1 time each of the following functions: print(), input(), len(), str(), int(), float() and randint(). - use at least 1 variable of each of the following data types: int, float and string. - use camelcase or underscores for variable names. Be consistent and have descriptive names! - use at least 4 different operators. One of them has to be the modulus or the integer division. - use a for loop inside your main loop to ask 3 questions using the range() function. Use the value of your iterator to ask the 3 questions. - use at least 1 time each of the following statements: if, else, elif, break and continue. - use at least one “Truthy” or “Falsey” value. Also, write some comments explaining what you do in your code and why. Submit your code file as hw1_name_surname.py. Comment everything so we know you wrote the code! On top of your file write this multiline comment with your information: ””” Homework 1, Exercise 1 (or 2…) Name Date Description of your program
The program must be written in python.
"""
This
is
multiline comment
"""
#array of secret questions
secretQuestions = ["Your favourite pet ?","Your childhood name
?","Your childhood friend ?"]
#array of answers compare with user input
answers = ["dog","nk","kp"]
#flag boolean variable storing TRUE or FALSE for user answer
flag = False
#inside for loop prompt messege to user then take input one by
one
for q in range(3):
ans = input(secretQuestions[q]+" : ") #take answer in ans
varibale
ans = ans.lower() #convert ans to lower case
if ans == answers[q] : #compare answer is correct
flag = True #assign true in flage when answer is correct
else :
flag = False #assign false in flage when wrong answer and print
msg
print("Enter correct answer,please try again !")
break #break the loop when answer is incorrect
print() #print() function for new line
print()
#when all answer is correct print all messege with answer
if flag == True :
print("Secret Question with answers \n")
for i in range(3) :
print(secretQuestions[i] +" : "+answers[i])
"""
Sample test
Your favourite pet ? : dog
Your childhood name ? : nk
Your childhood friend ? : KP
Secret Question with answers
Your favourite pet ? : dog
Your childhood name ? : nk
Your childhood friend ? : kp
"""