Jordan Sims
Jordan Sims

Reputation: 21

Boolean Inputs in Python

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.

Upvotes: 0

Views: 5735

Answers (3)

Jordan Sims
Jordan Sims

Reputation: 21

enter image description here

Thanks for the help everyone I found out the answer.

Upvotes: 0

Robin Zigmond
Robin Zigmond

Reputation: 18259

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)

Upvotes: 1

Aida
Aida

Reputation: 2434

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

Upvotes: 2

Related Questions