142k views
3 votes
Create a conditional expression that evaluates to string "negative" if user_val is less than 0, and "non-negative" otherwise.

Sample output with input: -9
-9 is negative

here is the code:
user_val = int(input())

cond_str = 'negative' if user_val < 0 else cond_str

print(user_val, 'is', cond_str)

User Barsan
by
5.3k points

1 Answer

2 votes

Answer:

The modified program is as follows:

user_val = int(input())

cond_str = 'non-negative'

if user_val < 0:

cond_str = 'negative'

print(user_val, 'is', cond_str)

Step-by-step explanation:

This gets input for user_val

user_val = int(input())

This initializes cond_str to 'non-negative'

cond_str = 'non-negative'

If user_val is less than 0

if user_val < 0:

cond_str is updated to 'negative'

cond_str = 'negative'

This prints the required output

print(user_val, 'is', cond_str)

User Alfredaday
by
5.8k points