英文:
Python Print Statement Spacing
问题
Python Code
phone_number = int(input())
last_four = phone_number % 10000
area_code = phone_number // 10000000
middle_three = (phone_number % 10000000) // 10000
print('(', area_code, ')', middle_three, '-', last_four)
代码中不需要更改,将输出 (800) 格式。
英文:
My Question
How do I remove the spaces in between 800 and the parenthesis surrounding the 800?
For example;
Instead of outputting ( 800 )
I would like it to be (800)
My code is below..
Python Code
phone_number = int(input())
last_four = phone_number % 10000
area_code = phone_number // 10000000
middle_three = (phone_number % 10000000) // 10000
print('(', area_code, ')', middle_three, '-', last_four)
答案1
得分: 2
print(f'({area_code}){middle_three}-{last_four}')
英文:
You can simply use f-strings which are quite powerful and will help you later on as well
print(f'({area_code}){middle_three}-{last_four}')
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论