Thursday, October 29, 2015 8:05 PM

Python Conditional expression (Activity 4.7.1)

Python
Question:
Create a conditional expression that evaluates to string "negative" if user_val is less than 0, and "non-negative" otherwise. Example output when user_val is -9 for the below sample program:
-9 is negative
 
Code:
user_val = -9

cond_str =0
if user_val<0:
cond_str='negative'
else:
cond_str='non-negative'



print(user_val, 'is', cond_str) 

About Unknown

Here you can share some biographical information next to your profile photo. Let your readers know your interests and accomplishments.

2 comments: