• Jun 1, 2023 •CodeCatch
0 likes • 3 views
def calculate_values(): value1 = 10 value2 = 20 return value1, value2 result1, result2 = calculate_values() print("Result 1:", result1) print("Result 2:", result2)
• Nov 18, 2022 •AustinLeath
0 likes • 5 views
import itertools import string import time def guess_password(real): chars = string.ascii_lowercase + string.ascii_uppercase + string.digits + string.punctuation attempts = 0 for password_length in range(1, 9): for guess in itertools.product(chars, repeat=password_length): startTime = time.time() attempts += 1 guess = ''.join(guess) if guess == real: return 'password is {}. found in {} guesses.'.format(guess, attempts) loopTime = (time.time() - startTime); print(guess, attempts, loopTime) print("\nIt will take A REALLY LONG TIME to crack a long password. Try this out with a 3 or 4 letter password and see how this program works.\n") val = input("Enter a password you want to crack that is 9 characters or below: ") print(guess_password(val.lower()))
• Nov 19, 2022 •CodeCatch
0 likes • 1 view
""" Calculator ---------------------------------------- """ def addition (): print("Addition") n = float(input("Enter the number: ")) t = 0 //Total number enter ans = 0 while n != 0: ans = ans + n t+=1 n = float(input("Enter another number (0 to calculate): ")) return [ans,t] def subtraction (): print("Subtraction"); n = float(input("Enter the number: ")) t = 0 //Total number enter sum = 0 while n != 0: ans = ans - n t+=1 n = float(input("Enter another number (0 to calculate): ")) return [ans,t] def multiplication (): print("Multiplication") n = float(input("Enter the number: ")) t = 0 //Total number enter ans = 1 while n != 0: ans = ans * n t+=1 n = float(input("Enter another number (0 to calculate): ")) return [ans,t] def average(): an = [] an = addition() t = an[1] a = an[0] ans = a / t return [ans,t] // main... while True: list = [] print(" My first python program!") print(" Simple Calculator in python by Malik Umer Farooq") print(" Enter 'a' for addition") print(" Enter 's' for substraction") print(" Enter 'm' for multiplication") print(" Enter 'v' for average") print(" Enter 'q' for quit") c = input(" ") if c != 'q': if c == 'a': list = addition() print("Ans = ", list[0], " total inputs ",list[1]) elif c == 's': list = subtraction() print("Ans = ", list[0], " total inputs ",list[1]) elif c == 'm': list = multiplication() print("Ans = ", list[0], " total inputs ",list[1]) elif c == 'v': list = average() print("Ans = ", list[0], " total inputs ",list[1]) else: print ("Sorry, invilid character") else: break
# Input for row and column R = int(input()) C = int(input()) # Using list comprehension for input matrix = [[int(input()) for x in range (C)] for y in range(R)]
0 likes • 4 views
list_1 = [1,2,3,4,5,6,7,8,9] cubed = map(lambda x: pow(x,3), list_1) print(list(cubed)) #Results #[1, 8, 27, 64, 125, 216, 343, 512, 729]
0 likes • 6 views
# Python Program to calculate the square root num = float(input('Enter a number: ')) num_sqrt = num ** 0.5 print('The square root of %0.3f is %0.3f'%(num ,num_sqrt))