Python Forum
[Basic] Control Flow in Python assignment
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Basic] Control Flow in Python assignment
#1
Hi, Python Learners! I'm building out assignments to help people learn Python. Here's the latest one on control flow, which includes conceptual questions and coding questions pertaining to functions, if statements, booleans, and loops. Enjoy!

https://open.openclass.ai/resource/assig...1VwbZ_3z8Q
Reply
#2
I tried the first example. The code I entered produced the correct result when run in my system but produced errors when run in you online interpreter. Here's my code:


# Move this code into a function `is_prime(test_num)`
def is_prime(test_num):
    num = 2
    test_num_is_prime = True
    while num <= float(test_num / 2):
        if test_num % num == 0:
            test_num_is_prime = False
            break
        num += 1
    if test_num_is_prime:
        print("%d is prime" % test_num)
    else:
        print("%d is not prime" % test_num)

# Input handling, do not modify below this line
is_prime(int(input()))
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020