OPEN AI SKRIPTZ Flashcards

1
Q

write python code that tracks my working sessions. use tkinker module for gui

A

from tkinter import *

Create a new Tkinter window
window = Tk()

Create a button that will start tracking your working session when clicked
start_button = Button(window, text=”Start Working”, command=start_tracking)
start_button.pack()

Create a label that will display the total time spent working
total_time_label = Label(window, text=”Total Time Spent Working: 0 minutes”)
total_time_label.pack()

Create a button that will stop tracking your working session when clicked
stop_button = Button(window, text=”Stop Working”, command=stop_tracking)
stop_button.pack()

Create a function that will start tracking your working session
def start_tracking():
# Set a global variable to track the start time of your working session
global start_time
start_time = time.time()

Create a function that will stop tracking your working session
def stop_tracking():
# Set a global variable to track the end time of your working session
global end_time
end_time = time.time()

# Calculate the total time spent working by subtracting the start time from the end time
total_time_spent_working = end_time - start_time

# Update the total time spent working label with the calculated value
total_time_label[“text”] = “Total Time Spent Working: “ + str(total_time_spent_working) + “ minutes”

Start the Tkinter main loop
window.mainloop()

konieckodu
This code creates a Tkinter window with three buttons: one to start tracking your working session, one to stop tracking your working session, and one to display the total time spent working. When you click the “Start Working” button, it will record the start time of your working session. When you click the “Stop Working” button, it will record the end time of your working session and calculate the total time spent working by subtracting the start time from the end time. It will then update the total time spent working label with the calculated value.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Write python code that logs Deep Work sessions. It should ask how long user will be working.

A

import time

def log_deep_work_session():
# Ask the user how long they will be working
work_duration = input(“How long will you be working? (in minutes): “)

# Convert the user’s input into an integer
work_duration = int(work_duration)

# Print the start time of the deep work session
print(“Starting deep work session at: “, time.strftime(“%I:%M %p”))

# Sleep for the specified duration
time.sleep(work_duration * 60)

# Print the end time of the deep work session
print(“Ending deep work session at: “, time.strftime(“%I:%M %p”))

Run the log_deep_work_session function
log_deep_work_session()

konieckodu
This script uses the input() function to ask the user how long they will be working, the int() function to convert the user’s input to an integer, the time module to access the current time, and the sleep() function to pause the script for the specified duration.

Note that this is just an example, and you may want to modify the code to suit your specific needs. For example, you could add more features, such as logging the start and end times of the deep work session to a file, or allowing the user to specify the start time of the session.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

write python game with gui

A

import pygame

Initialize Pygame
pygame.init()

Set the screen dimensions
SCREEN_WIDTH = 800
SCREEN_HEIGHT = 600

Create the screen
screen = pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT))

Set the title
pygame.display.set_caption(“Python Game”)

Set the background color
screen.fill((255, 255, 255))

Set the dimensions of the player’s rectangle
player_width = 50
player_height = 50

Set the initial position of the player’s rectangle
player_x = SCREEN_WIDTH // 2
player_y = SCREEN_HEIGHT // 2

Set the movement speed
player_speed = 5

Define the game loop
while True:
# Process events
for event in pygame.event.get():
# Check if the user wants to quit
if event.type == pygame.QUIT:
# End the game
pygame.quit()
exit()

# Update the player's position
player_x += player_speed

# Check if the player has reached the right edge of the screen
if player_x > SCREEN_WIDTH - player_width:
    player_speed = -player_speed

# Check if the player has reached the left edge of the screen
elif player_x < 0:
    player_speed = abs(player_speed)

# Draw the player's rectangle
pygame.draw.rect(screen, (0, 0, 0), (player_x, player_y, player_width, player_height))

# Update the screen
pygame.display.flip()

In this game, a black rectangle representing the player bounces back and forth across the screen. The player’s rectangle is initially positioned in the middle of the screen, and its movement is controlled by the player_speed variable, which is set to 5 pixels per frame.

Each time the game loop runs, the player’s position is updated by adding player_speed to the player_x coordinate. This causes the rectangle to move to the right. If the rectangle reaches the right edge of the screen, its movement direction is reversed by setting player_speed to a negative value. This causes the rectangle to move to the left.

The game loop also checks if the player has reached the left edge of the screen. If the player has, player_speed is set to its absolute value, which causes the rectangle to start moving to the right again.

Finally, the player’s rectangle is drawn to the screen at its current position, and the screen is updated to show the new frame.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

write a python code that counts prime numbers

A

def count_primes(n):
# Initialize a counter
count = 0

# Check if each number between 2 and n is prime
for i in range(2, n+1):
    # Initialize a flag to indicate whether i is prime
    is_prime = True
    
    # Check if i is divisible by any number between 2 and i
    for j in range(2, i):
        # If i is divisible by j, set is_prime to False
        # and break out of the inner loop
        if i % j == 0:
            is_prime = False
            break
    
    # If is_prime is still True, increment the counter
    if is_prime:
        count += 1

# Return the number of primes
return count

This function first initializes a counter variable to 0. It then loops over the numbers between 2 and n, inclusive, and checks if each number is prime.

To do this, the function uses a nested loop. The outer loop iterates over the numbers between 2 and n, and the inner loop checks if the current number is divisible by any number between 2 and the current number. If the current number is divisible by any of these numbers, the is_prime flag is set to False and the inner loop is broken.

If the is_prime flag is still True after the inner loop has completed, it means that the current number is prime. In this case, the counter is incremented by 1.

Finally, after all numbers between 2 and n have been checked, the function returns the value of the counter, which is the number of prime numbers between 2 and n.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

write a simple python program that guesses the number I’m thinking about

A

Set the minimum and maximum values for the guess
min_value = 1
max_value = 100

Set the initial guess to the midpoint between the minimum and maximum values
guess = (min_value + max_value) // 2

Print the initial guess
print(“Is your number “, guess, “?”)

Get the user’s response
response = input(“Enter ‘h’ if the guess is too high, ‘l’ if it is too low, or ‘c’ if it is correct: “)

Keep guessing until the user enters ‘c’
while response != ‘c’:
# Update the guess based on the user’s response
if response == ‘h’:
max_value = guess
elif response == ‘l’:
min_value = guess

# Update the guess to the midpoint between the new min and max values
guess = (min_value + max_value) // 2

# Print the updated guess
print("Is your number ", guess, "?")

# Get the user's response
response = input("Enter 'h' if the guess is too high, 'l' if it is too low, or 'c' if it is correct: ")

Print a message indicating that the guess was correct
print(“I guessed your number! It was “, guess)

konieckodu
This program uses the binary search algorithm to guess the number you’re thinking of. It first sets the minimum and maximum values for the guess to 1 and 100, respectively. It then sets the initial guess to the midpoint between these values.

The program then prints the initial guess and prompts the user for a response. If the user enters ‘h’, the program updates the maximum value for the guess to the current guess. If the user enters ‘l’, the program updates the minimum value for the guess to the current guess. In either case, the program updates the guess to the midpoint between the new minimum and maximum values.

The program repeats this process until the user enters ‘c’, indicating that the guess was correct. When this happens, the program prints a message indicating that it guessed the correct number.

This program can be modified to guess a number within a different range by changing the min_value and max_value variables. For example, to guess a number between 1 and 1000, you would set min_value to 1 and max_value to 1000.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

write python code that moves my mouse a little bit every 15 seconds for 1 hour

A

import pyautogui
import time

Set the duration of the program in seconds
duration = 60 * 60

Set the time interval between mouse movements in seconds
interval = 15

Set the distance to move the mouse in pixels
distance = 5

Start a timer
start_time = time.time()

Move the mouse every 15 seconds for 1 hour
while time.time() - start_time < duration:
# Move the mouse a little bit to the right
pyautogui.moveRel(distance, 0)

# Wait for 15 seconds
time.sleep(interval)

This program uses the pyautogui library to move the mouse. It starts by importing the pyautogui and time modules.

The program then sets the duration of the program in seconds to 60 * 60, which is equal to 1 hour. It also sets the interval between mouse movements to 15 seconds, and the distance to move the mouse in pixels to 5.

The program then starts a timer and enters a loop that will run for the duration of the program. Inside the loop, the program uses the pyautogui.moveRel() method to move the mouse a little bit to the right by 5 pixels. It then uses the time.sleep() method to pause the program for 15 seconds before moving the mouse again.

This process continues until the program has run for 1 hour, at which point the loop will exit and the program will end.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

write python code that sets delayed shutdown of a computer. it should ask after how many minutes it should be executed

A

import os
import time

Prompt the user for the number of minutes to delay the shutdown
minutes = int(input(“Enter the number of minutes to delay the shutdown: “))

Convert the number of minutes to seconds
delay = minutes * 60

Print a message indicating that the shutdown has been scheduled
print(“The computer will shut down in “, delay, “ seconds.”)

Wait for the specified delay
time.log(delay)

Shut down the computer
os.system(“shutdown /s /t 0”)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

wylaczenie komputera ale + napisz o ktorej sie wylaczy

A

import os
import time

Prompt the user for the number of minutes to delay the shutdown
minutes = int(input(“Enter the number of minutes to delay the shutdown: “))

Convert the number of minutes to seconds
delay = minutes * 60

Calculate the hour at which the shutdown will occur
shutdown_time = time.time() + delay
shutdown_hour = time.localtime(shutdown_time).tm_hour

Print a message indicating that the shutdown has been scheduled
print(“The computer will shut down at “, shutdown_hour, “ o’clock.”)

Wait for the specified delay
time.sleep(delay)

Shut down the computer
os.system(“shutdown /s /t 0”)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

write python code that opens websites that I insert

A

import webbrowser

Prompt the user for the URLs of the websites to open
url1 = input(“Enter the URL of the first website to open: “)
url2 = input(“Enter the URL of the second website to open: “)
url3 = input(“Enter the URL of the third website to open: “)

Open the websites in the default web browser
webbrowser.open(url1)
webbrowser.open(url2)
webbrowser.open(url3)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

create a python push-up counter that logs how many push-ups I made each day

A

import datetime

Initialize the push-up counter
pushup_count = 0

Start the push-up counter
print(“Start your push-ups now. When you’re done, press ‘Enter’.”)

Count the number of push-ups until the user presses ‘Enter’
while input() != ‘’:
pushup_count += 1

Print the number of push-ups
print(“You did “, pushup_count, “ push-ups.”)

Get the current date
date = datetime.datetime.now().strftime(“%Y-%m-%d”)

Open the push-up log file
with open(“pushup_log.txt”, “a”) as log_file:
# Write the number of push-ups and the date to the log file
log_file.write(str(pushup_count) + “,” + date + “\n”)

This program uses the datetime module to log the date on which the push-ups were performed. It starts by importing the datetime module.

The program then initializes a pushup_count variable to 0 and prints a message indicating that the user should start their push-ups. It enters a loop that counts the number of push-ups performed until the user presses Enter. Each time the user performs a push-up, the pushup_count variable is incremented by 1.

When the user is done with their push-ups and presses Enter, the program prints the total number of push-ups performed. It then uses the datetime.datetime.now() method to get the current date and time, and formats this value as a string in the YYYY-MM-DD format.

The program then opens the pushup_log.txt file in append mode and writes the number of push

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

write a python code that recognizes bank account numbers from text

A

import re

Prompt the user for the text to search for bank account numbers
text = input(“Enter the text to search for bank account numbers: “)

Use a regular expression to search for bank account numbers in the text
account_numbers = re.findall(r”\d{4}-\d{4}-\d{4}-\d{4}”, text)

Print the bank account numbers that were found
print(“Bank account numbers:”, account_numbers)

This program uses a regular expression to search for bank account numbers in the text. It starts by importing the re module, which provides support for regular expressions in Python.

The program then prompts the user for the text to search for bank account numbers and saves this value in the text variable. It uses the re.findall() method to search for bank account numbers in the text. This method uses a regular expression that matches bank account numbers in the format XXXX-XXXX-XXXX-XXXX, where X is a digit from 0 to 9.

The re.findall() method returns a list of all the bank account numbers that were found in the text. The program prints this list of bank account numbers.

You can modify this program to search for bank account numbers in a different format by changing the regular expression used in the re.findall() method. For example, to search for bank account numbers in the format XXXXXXXXXX, you could use the following regular expression: r”\d{10}”. This regular expression matches a string of exactly 10 digits.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly