# February Monthly Project # Winter Olympics logo and medal count # This sample code includes: # an intro # random location for logo # capability to compare two countries # random circles for medals from codex import * from random import randrange def logo(x1, y1): display.fill(LIGHT_GRAY) # Draw Olympic rings display.draw_circle(x1+50, y1+150, 35, BLUE) display.draw_circle(x1+125, y1+150, 35, BLACK) display.draw_circle(x1+200, y1+150, 35, RED) display.draw_circle(x1+85, y1+185, 35, YELLOW) display.draw_circle(x1+160, y1+185, 35, DARK_GREEN) # Draw text display.draw_text("MILANO CORTINA", x=34, y=25, color=BLACK, scale=2) display.draw_text("Winter Olympics", x=30, y=50, color=BLACK, scale=2) display.draw_text("2026", x=70, y=75, color=BLACK, scale=4) def console_input(): country_list = [] country_list.append(input("Which country? ")) country_list.append(int(input("How many gold medals? "))) country_list.append(int(input("How many silver medals? "))) country_list.append(int(input("How many bronze medals? "))) return country_list def get_info(choice): display.clear() display.print("Answer questions") display.print("in the console.") if choice == 1: country_list = console_input() return country_list else: print("First country") country_list1 = console_input() print("Second country") country_list2 = console_input() return country_list1, country_list2 def stacks_one(): country_list = get_info(1) print(country_list) display.clear() display.print(country_list[0]) display.print("Olympic medals") bar_chart(country_list[1], 20, YELLOW, ORANGE, 'Gold', 60) bar_chart(country_list[2], 95, LIGHT_GRAY, GRAY, 'Silver', 60) bar_chart(country_list[3], 170, ORANGE, RED, 'Bronze', 60) def stacks_two(): country_list1, country_list2 = get_info(2) display.clear() display.print(country_list1[0] + " and " + country_list2[0]) display.print("Olympic medals") bar_chart(country_list1[1], 20, YELLOW, ORANGE, country_list1[0], 30) bar_chart(country_list1[2], 95, LIGHT_GRAY, GRAY, country_list1[0], 30) bar_chart(country_list1[3], 170, ORANGE, RED, country_list1[0], 30) bar_chart(country_list2[1], 52, YELLOW, ORANGE, country_list2[0], 30) bar_chart(country_list2[2], 127, LIGHT_GRAY, GRAY, country_list2[0], 30) bar_chart(country_list2[3], 202, ORANGE, RED, country_list2[0], 30) def bar_chart(num, x1, color1, color2, text, width): y1 = 220 for i in range(num): display.fill_rect(x1, y1, width, 12, color1) display.draw_rect(x1, y1, width, 12, color2) y1 = y1 - 12 display.draw_text(text, x=x1+5, y=225, color=BLUE) display.draw_text(str(num), x=x1+10, y=y1, color=WHITE, scale=2) def draw_medals(num, low, high, color1, color2): for i in range(num): x = randrange(low, high) y = randrange(60, 220) display.fill_circle(x, y, 20, color1) display.draw_circle(x, y, 20, color2) def random_medals(): country_list = get_info(1) display.clear() display.print(country_list[0]) display.print("Olympic medals") draw_medals(country_list[1], 20, 75, YELLOW, ORANGE) draw_medals(country_list[2], 80, 155, LIGHT_GRAY, GRAY) draw_medals(country_list[3], 160, 235, ORANGE, RED) def intro(): display.clear() display.print("Welcome to") display.print("Winter Olympics") display.print() display.print("A=Logo") display.print("B=Random Logo") display.print("R=Medals-1 country") display.print("L=Medals-2 count.") display.print("U=Random medals") display.print("D=Intro") # === Main Program === intro() while True: if buttons.was_pressed(BTN_A): logo(0, 0) if buttons.was_pressed(BTN_B): x1 = randrange(-20, 100) y1 = randrange(-50, 150) logo(x1, y1) if buttons.was_pressed(BTN_R): stacks_one() if buttons.was_pressed(BTN_L): stacks_two() if buttons.was_pressed(BTN_D): intro() if buttons.was_pressed(BTN_U): random_medals()