Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Beginner Python: is there a cleaner way to to rewrite my current code? I am quite new to Python. Here I have written a code

Beginner Python: is there a "cleaner" way to to rewrite my current code?

I am quite new to Python. Here I have written a code that translates alpha characters to numerics in a phone number. My code will just assume that the format of the phone number is entered correctly.

def phone(phone_number): converted_phone_number = "" for number in phone_number: if number in "ABC": converted_phone_number += '2' elif number in "DEF": converted_phone_number += '3' elif number in "GHI": converted_phone_number += '4' elif number in "JKL": converted_phone_number += '5' elif number in "MNO": converted_phone_number += '6' elif number in "PQR": converted_phone_number += '7' elif number in "TUV": converted_phone_number += '8' elif number in "WXYZ": converted_phone_number += '9' else: converted_phone_number += number return converted_phone_number def main(): print(phone("604-GOT-JUNK")) if __name__ == "__main__": main()

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

Fundamentals Of Database Systems

Authors: Ramez Elmasri, Sham Navathe

4th Edition

0321122267, 978-0321122261

More Books

Students also viewed these Databases questions

Question

Explain how cultural differences affect business communication.

Answered: 1 week ago

Question

List and explain the goals of business communication.

Answered: 1 week ago