Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Description You are provided with a stub in which you need to insert your code where indicated without doing any changes to the existing code
Description
You are provided with a stub in which you need to insert your code where indicated
without doing any changes to the existing code to complete the task.
The current code will accept a zero or positive integer that is nonstrictly negative integer
with possible leading s and converts it to base keeping leading s if any
Given the following directions:
: Move North
: Move NorthEast
: Move East
: Move SouthEast
: Move South
: Move SouthWest
: Move West
: Move NorthWest
Reading the number written in base from right to left. We start from a position that is the
unique position where the switch is on Moving to a position switches on to off and off to
on there. By default, all positions are off.
Your program should display the minimal rectangular shape that includes all on positions as
shown in the test cases below.
Test Cases
Enter a nonstrictly negative integer:
Keeping leading s if any, in base reads as
Enter a nonstrictly negative integer:
Keeping leading s if any, in base reads as
Enter a nonstrictly negative integer:
Keeping leading s if any, in base reads as
Enter a nonstrictly negative integer:
Keeping leading s if any, in base reads as
Enter a nonstrictly negative integer:
Keeping leading s if any, in base reads as
Python code start here
# Reading the number written in base from right to left,
# keeping the leading s if any:
# : move N : move NE : move E : move SE
# : move S : move SW : move W : move NW
#
# We start from a position that is the unique position
# where the switch is on
#
# Moving to a position switches on to off, off to on there.
import sys
on uaa
off uab
code inputEnter a nonstrictly negative integer: strip
try:
if code:
raise ValueError
intcode
except ValueError:
printIncorrect input, giving up
sysexit
nbofleadingzeroes
for i in rangelencode:
if codei:
nbofleadingzeroes
else:
break
printKeeping leading s if any, in base code, 'reads as
nbofleadingzeroes fintcode:o
print
#printnbofleadingzeroes
# INSERT YOUR CODE HERE
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started