0% found this document useful (0 votes)
15 views19 pages

Python Programming Logic Exercises

The document contains multiple programming tasks in Python, including using loops to tighten bolts, simulate robot movement, and assess apple ripeness. It also includes debugging exercises for common coding errors related to loops and conditional statements. Each program and task is clearly outlined with specific requirements and expected outputs.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views19 pages

Python Programming Logic Exercises

The document contains multiple programming tasks in Python, including using loops to tighten bolts, simulate robot movement, and assess apple ripeness. It also includes debugging exercises for common coding errors related to loops and conditional statements. Each program and task is clearly outlined with specific requirements and expected outputs.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Let’s Develop Logic

Program 1

Task: Write a Python program using a for loop that prints "Tightening bolt #" followed
by the bolt number (1 to 6). After the loop finishes, print "Wheel Secured! Secured!"
Program 1

Task: Write a Python program using a for loop that prints "Tightening bolt #" followed
by the bolt number (1 to 6). After the loop finishes, print "Wheel Secured! Secured!"

print("Starting assembly...")
for i in range(1, 7):
print("Tightening bolt # ",i)
print("Wheel Secured!")
Program 2

Task: Create a variable distance and set it to 50 (cm). Write a while loop that
runs as long as the distance is greater than 10. Inside the loop, decrease the
distance by 10 in each iteration (simulating the robot moving forward) and print
the current [Link]!"
Program 2
Task: Create a variable distance and set it to 50 (cm). Write a while loop that runs as long as the
distance is greater than 10. Inside the loop, decrease the distance by 10 in each iteration (simulating the
robot moving forward) and print the current [Link]!"

distance = 50
while distance > 10:
print("Moving forward... Current distance: “,distance,” cm")
distance=distance- 10 # Robot moves closer to the wall

print("Obstacle detected! Engaging brakes.")


Program 3

An AI computer vision system is scanning a tray of 5 apples. It identifies them by their


ripeness level (expressed as a percentage).

● Task: Create a list called apples with the values [85, 40, 92, 30, 77]. Loop
through the list. If an apple is above 70%, print "Status: Ripe - Pack for Shipping." If it is
below 70%, print "Status: Unripe - Reject."
Program 3
Task: Create a list called apples with the values [85, 40, 92, 30, 77]. Loop through
the list. If an apple is above 70%, print "Status: Ripe - Pack for Shipping." If it is below 70%,
print "Status: Unripe - Reject."

apples = [85, 40, 92, 30, 77]


apple_count = 1

for ripeness in apples:


print("Scanning Apple ",apple_count)
if ripeness >= 70:
print("Status: Ripe - Pack for Shipping")
else:
print("Status: Unripe - Reject")
apple_count += 1
Program 4

Write a while loop that simulates time passing (from minute 1 to 10). Inside the loop, ask
the user to input the current battery percentage. If the battery falls below 15%, use the
break statement to stop the patrol immediately and print "Emergency Landing Initialized!"
Program 4
print("Drone Patrol Started.")
for minute in range(1, 11):
print("--Minute of Patrol-")
battery = int(input("Enter current battery %: "))

if battery < 15:


print("CRITICAL: Battery low!")
break # This stops the patrol immediately

print("Battery OK. Continuing patrol...")

print("Patrol Session Ended.")


Program 5
Program 6
Debug Error

A student wrote this code to simulate a robot checking its battery 5 times, but it has
errors. Identify the mistakes and provide the correct code.

# Incorrect Code
count = 1
while count < 5
print("Checking battery...")
count = count + 1
if count == 3:
break
Debug Error

A robot is programmed to move until it detects an obstacle at a distance of 5cm.

# Student Code
distance = 20
while distance > 5
print("Moving forward...")
distance = distance - 5
Debug Error

Scenario: A robotic arm needs to rotate its base joint 4 times to scan a room.

# Student Code
for i in range(1, 5)
print("Rotating base joint")
print("Rotation number: " + i)
Debug Error

The "Sensor Expert System" Logic

Scenario: This code is part of an Expert System that checks if a sensor reading is "High".

# Student Code
sensor_reading = 350
if sensor_reading = 350:
Print("Warning: Value High")
else
print("Value Normal")
Little Quiz
Little Quiz
Little Quiz
Little Quiz

You might also like