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
#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


Messages In This Thread
RE: Control Flow in Python assignment - by BashBedlam - Jan-24-2021, 08:09 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Object-Oriented Programming in Python Assignment alectheprogrammer 0 1,731 Jan-03-2021, 04:56 AM
Last Post: alectheprogrammer

Forum Jump:

User Panel Messages

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