Remove @ before python question string

Asked 2 years ago, Updated 2 years ago, 15 views

username = input()

while True:

    myorder = input()

    if myorder.startswith('@'):
        print(myorder + ' ' + username + '.' )

If you put your name in username and @Hi in myorder, @Hi name. will be like '@Hi name.' even if you put @Hi into the input, isn't there any printed?

python

2022-09-20 17:38

1 Answers

print(myorder + ' ' + username + '.' )

You can change the code above as below.

print(myorder[1:] + ' ' + username + '.' )

Please refer to the code below and the result.

username = input()

while True:

    myorder = input()

    if myorder.startswith('@'):
        print(myorder[1:] + ' ' + username + '.' )


2022-09-20 17:38

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.