0
what is wrong with my code?
here is the code I wrote #the list of breakfasts breakfasts = [ 'Donuts', 'Waffles', 'Yogurt', 'Burrito', 'Toast'] #index of the item to be replaced item = int(input('Enter the correct index to replace (0-4): ')) # check that index is valid: if 0<= item <= 4: breakfasts [item] = 'Pancakes' #display the updated list print (breakfasts) else: print ("Invalid index") When I run it on PyCharm, it works, but here I get an error.
4 Answers
+ 3
Sololearner ,
if the exercise is a code coach, only required outputs are allowed:
> remove the prompt string in the input function
> general hint: we should always mention the tutorial name, module name, lesson / exercise name. without these information we have to guess ...
+ 1
Your code seems fine, but the issue might be due to environment configurations or input validation. Ensure the Python version and settings are consistent, and consider adding more robust input handling to prevent potential errors.
0
import pygame
import math
# Initialize Pygame
pygame.init()
screen_width, screen_height = 800, 600
screen = pygame.display.set_mode((screen_width, screen_height))
pygame.display.set_caption("Blowing Indian Flag")
# Colors
SAFFRON = (255, 153, 51)
WHITE = (255, 255, 255)
GREEN = (18, 136, 7)
ASHOKA_CHAKRA_COLOR = (0, 0, 128)
# Flag dimensions
flag_width, flag_height = 400, 267
flag_x, flag_y = 200, 150
stripe_height = flag_height // 3
# Animation variables
time = 0
amplitude = 10 # How much the flag "waves"
wave_speed = 0.05
frequency = 0.02
# Main loop
running = True
while running:
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
# Clear screen
screen.fill((0, 0, 0))
# --- Animation Logic ---
time += 1
# Draw the flag as a series of vertical lines to simulate the wave
for x in range(flag_width):
# Calculate the offset for each vertical line to create the wave effect
y_offset = amplitude * math.sin(x * fr
0
What's the error on the module<pygame>