• Nov 19, 2022 •CodeCatch
0 likes • 0 views
""" 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!"
• 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])
• Oct 7, 2022 •KETRICK
0 likes • 5 views
x[cat_var].isnull().sum().sort_values(ascending=False)
• Oct 10, 2025 •AustinLeath
0 likes • 2 views
#Original def output_json_log_data_to_file(filename, record_dictionary_list): with open(filename, 'w') as outputFile: for record in record_dictionary_list: json.dump(record, outputFile) outputFile.write('\n') #Atomic def output_json_log_data_to_file(filename, record_dictionary_list): # Use atomic file operations to prevent race conditions with readers # Write to temporary file first, then atomically rename to target file tmp_filename = filename + '.tmp' with open(tmp_filename, 'w') as outputFile: for record in record_dictionary_list: json.dump(record, outputFile) outputFile.write('\n') # Atomic rename - this prevents readers from seeing partial writes shutil.move(tmp_filename, filename)
• May 31, 2023 •CodeCatch
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()
• Sep 14, 2024 •rgannedo-6205
https://codecatch.net/post/06c9f5b7-1e00-40dc-b436-b8cccc4b69be