• Jul 24, 2024 •AustinLeath
0 likes • 3 views
from statistics import median, mean, mode def print_stats(array): print(array) print("median =", median(array)) print("mean =", mean(array)) print("mode =", mode(array)) print() print_stats([1, 2, 3, 3, 4]) print_stats([1, 2, 3, 3])
• Nov 19, 2022 •CodeCatch
from math import pi def rads_to_degrees(rad): return (rad * 180.0) / pi rads_to_degrees(pi / 2) # 90.0
• May 31, 2023 •CodeCatch
0 likes • 0 views
import calendar # Prompt user for year and month year = int(input("Enter the year: ")) month = int(input("Enter the month: ")) # Create a calendar object cal = calendar.monthcalendar(year, month) # Display the calendar print(calendar.month_name[month], year) print("Mon Tue Wed Thu Fri Sat Sun") for week in cal: for day in week: if day == 0: print(" ", end="") else: print(str(day).rjust(2), " ", end="") print()
""" Rock Paper Scissors ---------------------------------------- """ import random import os import re os.system('cls' if os.name=='nt' else 'clear') while (1 < 2): print "\n" print "Rock, Paper, Scissors - Shoot!" userChoice = raw_input("Choose your weapon [R]ock], [P]aper, or [S]cissors: ") if not re.match("[SsRrPp]", userChoice): print "Please choose a letter:" print "[R]ock, [S]cissors or [P]aper." continue // Echo the user's choice print "You chose: " + userChoice choices = ['R', 'P', 'S'] opponenetChoice = random.choice(choices) print "I chose: " + opponenetChoice if opponenetChoice == str.upper(userChoice): print "Tie! " #if opponenetChoice == str("R") and str.upper(userChoice) == "P" elif opponenetChoice == 'R' and userChoice.upper() == 'S': print "Scissors beats rock, I win! " continue elif opponenetChoice == 'S' and userChoice.upper() == 'P': print "Scissors beats paper! I win! " continue elif opponenetChoice == 'P' and userChoice.upper() == 'R': print "Paper beat rock, I win! " continue else: print "You win!"
0 likes • 4 views
def clamp_number(num, a, b): return max(min(num, max(a, b)), min(a, b)) clamp_number(2, 3, 5) # 3 clamp_number(1, -1, -5) # -1
• Feb 26, 2023 •wabdelh
0 likes • 1 view
#84 48 13 20 61 20 33 97 34 45 6 63 71 66 24 57 92 74 6 25 51 86 48 15 64 55 77 30 56 53 37 99 9 59 57 61 30 97 50 63 59 62 39 32 34 4 96 51 8 86 10 62 16 55 81 88 71 25 27 78 79 88 92 50 16 8 67 82 67 37 84 3 33 4 78 98 39 64 98 94 24 82 45 3 53 74 96 9 10 94 13 79 15 27 56 66 32 81 77 # xor a list of integers to find the lonely integer res = a[0] for i in range(1,len(a)): res = res ^ a[i]