#πŸ”’ how do i make lines 3 and 5 shorter?

30 messages Β· Page 1 of 1 (latest)

crisp roost
#

i am doing a task on a website and its interpeter doesnt allow lines to be longer than 121 characters long, so how can i shorten them?

x = input()

if ('giant' in x or 'Giant' in x or 'GIANT' in x) and ('lilliput' not in x or 'Lilliput' not in x or 'LILLIPUT' not in x):
    print("In the land of giants.")
elif ('lilliput' in x or 'Lilliput' in x or 'LILLIPUT' in x) and ('giant' not in x or 'Giant' not in x or 'GIANT' not in x):
    print("In the land of the Lilliput.")
else:
    print("I'm completely confused.")
versed tundraBOT
#

@crisp roost

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

snow bough
#

This code is a bit too long to stay within the 121-character limit; use the .lower() for simplifying checks on various capitalizations, and break up long conditions using helper variables. Here is the refactored version of the above code:

#

`x = input().lower()

is_giant = 'giant' in x
is_lilliput = 'lilliput' in x

if is_giant and not is_lilliput:
print("In the land of giants.")
elif is_lilliput and not is_giant:
print("In the land of the Lilliput.")
else:
print("I'm completely confused.")`

digital magnet
digital magnet
#

in that case, the condition here is just verifying for different casings of x, so you could simplify it with x.lower()

crisp roost
#

string methods dont work

trim mulch
crisp roost
#

but i found myself using string variavbles

#

and it works

crisp roost
trim mulch
digital magnet
# crisp roost string methods dont work

Does the website perhaps not allow x.lower() or does it straight up error? If this is for a homework or from a course or something, I guess it not being allowed is understandable.

crisp roost
#

does not allow

trim mulch
#

Ah

crisp roost
#

now i have a different problem, since if there are both giant and lilliput it should print I'm completely confused. but it prints In the land of giants. instead

#

x = input()

ygiant = ('giant' in x or 'Giant' in x or 'GIANT' in x)
nlilliput = ('lilliput' not in x or 'Lilliput' not in x or 'LILLIPUT' not in x)

ngiant = ('giant' not in x or 'Giant' not in x or 'GIANT' not in x)
ylilliput = ('lilliput' in x or 'Lilliput' in x or 'LILLIPUT' in x)

if ygiant and nlilliput:
    print("In the land of giants.")
elif ylilliput and ngiant:
    print("In the land of the Lilliput.")
elif ygiant and ylilliput:
    print("I'm completely confused.")
else:
    print("I'm completely confused.")```
trim mulch
#

Can we have the question instead?

#

The actual task questions

crisp roost
#

If the string contains lilliput, Lilliput or LILLIPUT in any case, output In the land of Lilliput.

If it has giant, Giant or GIANT, output In the land of giants.

If the string contains both or none of them, output: I'm completely confused.

trim mulch
#

I got 349 with no lower, upper and capitalize

digital magnet
#

So you'd want and rather than just or since and would indeed return false (as not all parts of the condition are true)

versed tundraBOT
#
Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.

#

πŸ”’ how do i make lines 3 and 5 shorter?