[Solved] COMP1007 Lab 2- Program Control and Logic
5.0
1 customer review
Digital download
Digital download
$25.00
Upload assignment
| Addition | + | >>> 10 + 212 |
| Subtraction | >>> 10 28 | |
| Multiplication | * | >>> 10 * 220 |
| Division | / | >>> 10 / 25.0 |
| Modulus | % | >>> 5 % 32 |
| Exponentiation | ** | >>> 10 ** 2100 |
| Floor division | // | >>> 5 // 31 |
| Equal | == | >>> x = 1>>> x == 1True>>> x == 2False |
| Not Equal | != | False>>> x != 2True |
| Greater than | > | >>> x = 1>>> x > 1False |
| Greater than or equal to | >= | >>> x = 1>>> x >= 1True |
| Less than | < | >>> x = 1>>> x < 1False |
| and | If both operands are True, then the result is True. Otherwise, the result if False. | >>> x = 5>>> x < 10 and x > 3True |
| or | If both operands are False, then the result if False. Otherwise, the result if True. | >>> x = 5>>> x == 1 or x == 5True |
| not | The result is the reverse of the operand. | >>> x = 5>>> not x > 10True |
| score = input(Please input the score: ) score = float(score)if score >= 50: print(PASS)print(Congratulations!) else:print(FAIL)print(Please work harder!) |
| score = input(Please input the score: ) score = float(score)if score >= 85: print(A) elif score >= 75: print(B) elif score >= 65: print(C) elif score >= 50: print(D) else:print(F) |
| i = 1 while i <= 10: print(i)i = i+1print(i) |
| days = [Monday, Tuesday, Wednesday, Thursday, Friday, Saturday,Sunday] for d in days: print(d) |
| days = [Monday, Tuesday, Wednesday, Thursday, Friday, Saturday,Sunday] for i in range(7): print(days[i]) |
| #%%1 for i in range(1, 10):2 if i > 3: 3 break4 print(i)5 print(Broke out at x = {}.format(i)) |
| 123Broke out at x = 4 |
| #%% i = 0 while i < 6: i = i+1if i == 3:continueprint(i) |
| 12456 |
| Score range | Grade |
| 85 or above | A |
| 75 to 84 | B |
| 65 to 74 | C |
| 50 to 64 | D |
| Below 50 | F |
| scores = [50, 100, 75, 66, 88, 85, 46, 91, 0, 23] total = 0;for s in scores:total += s if s >= 85:grade = Aelif s >= 75:grade = Belif s >= 65:grade = Celif s >= 50:grade = Delse:grade = F print(i, grade, sep=t) print(Class average is , total / len(scores)) |
| 50 D100 A75 B66 C88 A85 A46 F91 A0 F23 FClass average is 62.4 |
| #%%total = 0 # total markscount = 0 # to count the number of students while True:s = input(Enter score, 1 to end: )s = int(s) if s < 0: break total += scount += 1 |
|
|
| 1234567 | import time # import the time module of Python for i in range(10):for j in range(i):print(*, end=)time.sleep(0.5) # pause for 0.5 second print() |
| Rule | Input | Reply |
| 1 | How are you? | Fine, and you? |
| 2 | How do you do. | How do you do. |
| 3 | Good to see you. | Me too. |
| 4 | others |