• Nov 18, 2022 •AustinLeath
0 likes • 1 view
# List lst = [1, 2, 3, 'Alice', 'Alice'] # One-Liner indices = [i for i in range(len(lst)) if lst[i]=='Alice'] # Result print(indices) # [3, 4]
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))
• May 31, 2023 •CodeCatch
0 likes • 2 views
import random # Define the ranks, suits, and create a deck ranks = ['Ace', '2', '3', '4', '5', '6', '7', '8', '9', '10', 'Jack', 'Queen', 'King'] suits = ['Hearts', 'Diamonds', 'Clubs', 'Spades'] deck = [(rank, suit) for rank in ranks for suit in suits] # Shuffle the deck random.shuffle(deck) # Display the shuffled deck for card in deck: print(card[0], "of", card[1])
• Jan 20, 2021 •Ntindle
0 likes • 5 views
print(“Hello World”)
• Sep 22, 2023 •AustinLeath
0 likes • 36 views
# Python binary search function def binary_search(arr, target): left = 0 right = len(arr) - 1 while left <= right: mid = (left + right) // 2 if arr[mid] == target: return mid elif arr[mid] < target: left = mid + 1 else: right = mid - 1 return -1 # Usage arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15] target = 7 result = binary_search(arr, target) if result != -1: print(f"Element is present at index {result}") else: print("Element is not present in array") #looks like everything is working, and working quite well # yea that compile channel is nice # try to disable public edits # on it, 5 secondsasdasdasdasf #going to re-enable the editing now for publicasdasdasdasdasdasd # yea probably some type of stale state, yep. I actually will take a look at thyis tmrw. I don't think it will be hard to fix #cool, I am going to disable public edits again now that I have the console pulled up. going to watch for crash. # sounsdsdsdsdsdsds
• Nov 19, 2022 •CodeCatch
import mysql.connector mydb = mysql.connector.connect( host="localhost", user="yourusername", password="yourpassword" ) mycursor = mydb.cursor() mycursor.execute("CREATE DATABASE mydatabase")