• Nov 18, 2022 •AustinLeath
0 likes • 3 views
primes=[] products=[] def prime(num): if num > 1: for i in range(2,num): if (num % i) == 0: return False else: primes.append(num) return True for n in range(30,1000): if len(primes) >= 20: break; else: prime(n) for previous, current in zip(primes[::2], primes[1::2]): products.append(previous * current) print (products)
• Feb 26, 2023 •wabdelh
0 likes • 0 views
#You are given a two-digit integer n. Return the sum of its digits. #Example #For n = 29 the output should be solution (n) = 11 def solution(n): return (n//10 + n%10)
• Nov 19, 2022 •CodeCatch
def print_x_pattern(size): i,j = 0,size - 1 while j >= 0 and i < size: initial_spaces = ' '*min(i,j) middle_spaces = ' '*(abs(i - j) - 1) final_spaces = ' '*(size - 1 - max(i,j)) if j == i: print(initial_spaces + '*' + final_spaces) else: print(initial_spaces + '*' + middle_spaces + '*' + final_spaces) i += 1 j -= 1 print_x_pattern(7)
• 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()
0 likes • 1 view
import mysql.connector mydb = mysql.connector.connect( host="localhost", user="yourusername", password="yourpassword" ) mycursor = mydb.cursor() mycursor.execute("CREATE DATABASE mydatabase")
import math def factorial(n): print(math.factorial(n)) return (math.factorial(n)) factorial(5) factorial(10) factorial(15)