Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Can you help me fix my code? I've done my own editing but I can't quite figure out why the Roman Numerals for the code

Can you help me fix my code? I've done my own editing but I can't quite figure out why the Roman Numerals for the code come out wrong.

from turtle import * # Draw a space between numerals def draw_space(): penup() forward(0) pendown() # Draw the Roman numerals def draw_numeral(numeral): if numeral == 'I': draw_I() elif numeral == 'V': draw_V() elif numeral == 'X': draw_X() elif numeral == 'L': draw_L() elif numeral == 'C': draw_C() elif numeral == 'D': draw_D() elif numeral == 'M': draw_M() def draw_I(): width(5) forward(40) #40 backward(20) left(90) forward(50) right(90) backward(20) forward(40) penup() forward(20) right(90) forward(50) left(90) pendown() draw_space() def draw_V(): width(5) left(75) forward(50) backward(50) left(30) forward(50) backward(50) right(105) draw_space() def draw_X(): penup() forward(0) pendown() width(5) left(75) forward(50) backward(25) left(30) forward(25) backward(50) penup() right(105) forward(20) #60 pendown() draw_space() def draw_L(): width(5) left(90) forward(50) backward(50) right(90) forward(35) penup() forward(30) pendown() draw_space() def draw_C(): width(5) penup() forward(25) pendown() left(180) circle(-25, 180) penup() forward(30) right(90) forward(50) left(90) pendown() draw_space() def draw_D(): width(5) circle(25, 180) left(90) forward(50) penup() left(90) forward(50) pendown() draw_space() def draw_M(): width(5) left(90) forward(50) right(150) forward(50) left(120) forward(50) right(150) forward(50) left(90) penup() forward(10) pendown() draw_space() # Convert integers to roman numerals def convert_to_roman(num): val = [1000, 500, 100, 50, 10, 5, 1] syb = ['M', 'D', 'C', 'L', 'X', 'V', 'I'] roman_num = '' i = 0 while num > 0: for _ in range(num // val[i]): roman_num += syb[i] num -= val[i] i += 1 return roman_num # ask the user for input def draw_current_time_or_date(): user_input = input("Enter the current time in HH:MM format (24-hour clock) or a date in MM/DD/YYYY format: ") try: # Try parsing as time hour, minute = map(int, user_input.split(':')) time_in_roman = convert_to_roman(hour) + convert_to_roman(minute) except ValueError: # If parsing as time fails, try parsing as date month, day, year = map(int, user_input.split('/')) time_in_roman = convert_to_roman(month) + convert_to_roman(day) + convert_to_roman(year) x = -40 * len(time_in_roman) // 2 y = 0 for numeral in time_in_roman: setpos(x, y) draw_numeral(numeral) x += 60 done() draw_current_time_or_date() exitonclick()

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

2. Why is resilience sometimes described as ordinary magic?

Answered: 1 week ago