Created
June 20, 2020 20:40
-
-
Save leonpanokarren/accd76f711de2a64f00c9306468b65f7 to your computer and use it in GitHub Desktop.
Hansel practice test 01
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
#### QUESTION NO 5 LIST LESS THAN 10### | |
new_list = [] | |
number_list = [1 ,2 ,3 ,5 ,8 , 13 , 21 , 34 , 55 ,89] | |
input_number = int(input("Enter a number for list\n")) | |
if input_number not in number_list: | |
print("Entered number is not present in listing") | |
else: | |
for number in number_list: | |
if number < input_number: | |
new_list.append(number) | |
print(new_list) | |
####################################################################################################################### | |
#Question no 6 Fibonacci series | |
from prac import num | |
def fibonacci(): | |
num = int(input("How many number do u want to generate ?:")) | |
i = 1 | |
if num == 0: | |
fib = [] | |
elif num == 1: | |
fib = [1] | |
elif num == 2: | |
fib = [1,1] | |
elif num > 2: | |
fib = [1,1] | |
while i < (num - 1): | |
fib.append(fib[i] + fib[i-1]) | |
i += 1 | |
return fib | |
print(fibonacci()) | |
input() | |
####################################################################################################################### | |
#PASSSWORD GENERATOR QUESTION NO 7 # | |
import random | |
characters = ["A", "B", "C", "D", "E", "F", "G", "H", "I", 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '!', '@', '#', '$', '%', '&', '*', '(', ')'] | |
strength = input("Do u want a weak , medium , strong password :").lower() | |
new_password = [] | |
def password(strength): | |
if strength == 'weak':#First we'll define the strength just putting this comment this here only for the rest also | |
while len(new_password) != 5: | |
new_password.append(characters[random.randint(1, 70)]) | |
elif strength == 'medium': | |
while len(new_password) != 8: | |
new_password.append(characters[random.randint(1, 70)]) | |
elif strength == 'strong': | |
while len(new_password) != 14: | |
new_password.append(characters[random.randint(1, 70)]) | |
return new_password | |
password(strength) | |
new_password = "".join(new_password) | |
print(new_password) | |
############## question no 3 CHARACTER INPUT ########################################################################## | |
username = input("please enter your name") | |
userage = input("please enter your age") | |
def age(userage) | |
turn = 100-userage+2020 | |
return turn | |
turn = age(userage) | |
message = 'hello %s , your age is %d and you will turn 100 in the year %d' %(username,userage,turn) | |
print(message) | |
############### QUESTION NO 4 EVEN OR ODD########################################################################### | |
num = int(input("Give me a number to check: " )) | |
check = input("give me a number to divide by") | |
if num % 4 ==0: | |
print(num, "is a multiple of 4") | |
elif num % 2 ==0: | |
print(num,"is an even number") | |
else: | |
print( num ,"is an odd number") | |
if num % check ==0 | |
print(num , "the given number divides evenly by" ,check) | |
else: | |
print(num, "the given number does not divide evenly" ,check) | |
######################### QUESTION NO 1 DIFFERNECE BETWEEN MIN AND MAX ######################################### | |
def most_numbers(*args): | |
if len(args) >0 : | |
max_a = max(args) | |
min_a = min(args) | |
return max_a - min_a | |
else: | |
return 0 | |
################################################################################################################ | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment