0

I am trying to solve this Boolean Input question but I can't figure out the answer. Here is what it says, We pass in 2 boolean inputs, cold and rainy.

You should output a single string: ('cold' or 'warm') ' and ' ('rainy' or 'dry') based on these inputs.

('cold' or 'warm') means you should use on of the two words, depending on the input boolean value.

for example False, True = 'warm and rainy'

And here is my code:

isCold= sys.argv[1] == 'True'
isRainy= sys.argv[2] == 'True'

if isCold:
  print('cold and rainy')

elif isRainy:
  print('warm and rainy')

else:
  print(cold and dry)

I don't know what I can do to solve this.

4
  • 1
    Please add some more info. Commented Sep 14, 2018 at 19:30
  • 1
    what are you passing as an argument ? Commented Sep 14, 2018 at 19:34
  • and what is the output you’re getting? Commented Sep 14, 2018 at 19:35
  • Expected Output: cold and dry Your Program Output: cold and rainy Commented Sep 15, 2018 at 0:41

3 Answers 3

2

Try this code:

import sys


def func1(isCold, isRainy):
    s = ''
    if isCold:
        s = s + 'cold and '
    else:
        s = s + 'warm and '

    if isRainy:
      s = s + 'rainy'
    else:
     s = s + 'dry'

    print(s)

isCold= sys.argv[1] == 'True'
isRainy= sys.argv[2] == 'True'

func1(isCold, isRainy)

Then, run it by using the following command in your linux terminal:

python3 your_file_name.py False True

Or if you are a Windows user:

your_file_name.py False True
Sign up to request clarification or add additional context in comments.

Comments

1

The concisest answer I can think of is:

temperature_description = "warm" if isWarm else "cold"
rain_description = "rainy" if isRainy else "dry"
print "{} and {}".format(temperature_description, rain_description)

Comments

0

enter image description here

Thanks for the help everyone I found out the answer.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.