121k views
10 votes
Convert the following code segments as instructed.

a. Write one if statement:
10 value > 0)
if value < 10)
print did it
b. Write multiple if statements:
if (len (mylstr) > 0) and (mylstr! "password")) :
print (did it)
c. Write multiple if statements (watch out, this may be trickier than it looks):
or (myue="password")) :
1 Kienyusa)
print (
MM)

User Haochen Wu
by
6.1k points

1 Answer

9 votes

Answer:

Following are the code to this question:

For point a:

value=7#defining a variable value that holds an integer value

if(value>0 and value<10):#use if block with and operator to check the value

print("did it")#print message

For point b:

my_str="not_password"#defining a variable my_str that holds string value

if (len(my_str) > 0):#defining if block that checks string variable length is greater than 0

if (my_str!= "password"):#defining if block to check my_str is not equal to another given value

print("did it")#print message

For point c:

my_str="not_password"#defining a variable my_str that holds string value

if (len(my_str) > 0):#defining if block that checks string variable length is greater than 0

print("did it")#print message

elif (my_str!="password"):#use elif block to check my_str is not equal to another given value

print("did it")#print message

Output:

did it

did it

did it

Explanation:

Please find the complete and the correct question in the attached file.

In point a, the "value" variable is defined, that holds an integer value , and it uses if block with "and" operator to check the value is greater than 0 and less than 10, and at the last, it will print the message "did it".

In point b, the "my_str" variable is declared, that holds a string value , and use the multiple if block in this, it checks the length is greater than 0, and in another, if it checks its "my_str" value is not equal to another given value, and it prints the message "did it".

In point c, the "my_str" variable is declared, that holds a string value , and use the if block, it checks the length is greater than 0, it will print the message "did it". In the elif block, it checks "my_str" value is not equal to another given value, and it prints the message "did it".

Convert the following code segments as instructed. a. Write one if statement: 10 value-example-1
User Gonglexin
by
6.0k points