Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Python beginner palindrome problem using string slicing https://media.discordapp.net/attachments/518651459429204000/553422729236185088/20190307_214351.jpg?width=504&height=676 The beginning code I have so far is: miles = 100000 # initializes sentry variable while miles

Python beginner palindrome problem using string slicing

https://media.discordapp.net/attachments/518651459429204000/553422729236185088/20190307_214351.jpg?width=504&height=676

The beginning code I have so far is:

miles = 100000 # initializes sentry variable

while miles < 1000000: # runs the loop if miles is under 1 million if str(miles)[2::] == str(miles)[2::-1]: # converts miles to a string and sees if the last 4 digits are equal to the last 4 digits of reverse miles print(miles)

if str(miles + 1)[1::] == str(miles + 1)[1::-1]: # converts miles to a string and sees if the last 5 digits are equal to the last 5 digits of reverse miles if str(miles + 2)[1:5:] == str(miles + 2)[1:5:-1]: # converts miles to a string and sees if the middle 4 digits are equal to the middle 4 digits of reverse miles if str(miles + 3) == str(miles + 3)[::-1]: # converts miles to a string and sees if all 6 digits are equal to the all 6 digits of reverse miles print("The original number on the odometer is", miles) miles += 1 # updates sentry variable

The print after the first if statement was to test if any numbers were completing that condition, but nothing was printing. We have not learned string slicing in my class yet so I may be doing this all wrong. Any help with solving this problem would be appreciated.

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_2

Step: 3

blur-text-image_3

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

Learning MySQL Get A Handle On Your Data

Authors: Seyed M M Tahaghoghi

1st Edition

0596529465, 9780596529468

More Books

Students also viewed these Databases questions

Question

Describe the ethical issues involved in conducting HRD evaluation

Answered: 1 week ago