Lesson 1 – Printing and Running Python
1 2 3 4 5 6 7 8 9 10 11 12 13 |
from ultralytics import YOLO print("Program start...") # Load model model = YOLO("yolov8s.pt") # Run detection results = model(r"C:\AI\PICS\pic1.png") # Show detections results[0].show() |
this is an A.I simple model code out goal is to learn A.I , and A.I programing
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
# Learn Python to A.I Programming - Robotronix.co.il , Yaniv Maor # Example 1 – Print simple text print("Hello, world!") # Example 2 – Print a learning sentence print("I am learning Python for Artificial Intelligence.") # Example 3 – Print a number print(2025) # Example 4 – Print result of math print(5 + 3) # Example 5 – Print multiple words print("Python", "is", "fun") |
Output:
Example 1: Hello, world!
Example 2: I am learning Python for Artificial Intelligence.
Example 3: 2025
Example 4: 8
Example 5: Python is fun
1 2 3 4 5 6 7 8 9 10 11 12 |
# Learn Python to A.I Programming - Robotronix.co.il , Yaniv Maor # Example 1 – Print text + number print("The result is", 4 * 5) # Example 2 – Print with newline print("Hello\nWorld") # Example 3 – Print a quote inside text print('She said "Python is amazing!"') # Example 4 – Repeat word using multiplication print("AI " * 3) |
Output:
Example 1: The result is 20
Example 2: Hello
World
Example 3: She said "Python is amazing!"
Example 4: AI AI AI
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
# Learn Python to A.I Programming - Robotronix.co.il , Yaniv Maor # Example 1 – Print a floating-point number print(3.14159) # Example 2 – Round a number to nearest integer print(round(3.8)) # Example 3 – Round a float to 2 decimal places print(round(3.14159, 2)) # Example 4 – Format float using f-string to show 2 digits value = 12.34567 print(f"Value = {value:.2f}") # Example 5 – Combine text and rounded math result num = 10 / 3 print("10 divided by 3 is", round(num, 2)) |
Output:
Example 1: 1.1 2.22 3.333
Example 2: Average: 6.25
Example 3: Height: 1.76 m
Example 4: Age: 30, Weight: 72.6 kg
Example 5: Accuracy: 87.65%
Exercises – Lesson 1: Printing and Numbers
Exercise 1:
Write a program that prints your name and age on one line.
Exercise 2:
Print the result of 12.5 / 3
rounded to 2 decimal places.
Exercise 3:
Display the text "AI Power Level:"
followed by the number 99.876
rounded to one decimal place.
Exercise 4:
Print three numbers (4, 8, 12) separated by commas, and then print their average rounded to 2 digits.
Exercise 5:
Show a floating number formatted as currency — for example 5.6789
→ "$5.68"
.
Solutions
1 2 3 4 5 |
# Learn Python to A.I Programming - Robotronix.co.il , Yaniv Maor # Solution 1 – Print name and age print("My name is Yaniv, I am", 50, "years old") # Output: My name is Yaniv, I am 50 years old # Remark: Uses commas to combine text and numbers. |
1 2 3 4 5 6 |
# Learn Python to A.I Programming - Robotronix.co.il , Yaniv Maor # Solution 2 – Divide and round to 2 decimals result = 12.5 / 3 print("Rounded result:", round(result, 2)) # Output: Rounded result: 4.17 # Remark: round(number, 2) limits to 2 decimal digits. |
1 2 3 4 5 6 |
# Learn Python to A.I Programming - Robotronix.co.il , Yaniv Maor # Solution 3 – Round one decimal and print with text power = 99.876 print(f"AI Power Level: {power:.1f}") # Output: AI Power Level: 99.9 # Remark: f-string controls decimal precision with .1f. |
1 2 3 4 5 6 7 |
# Learn Python to A.I Programming - Robotronix.co.il , Yaniv Maor # Solution 4 – Average of three numbers a, b, c = 4, 8, 12 avg = (a + b + c) / 3 print(f"Average = {avg:.2f}") # Output: Average = 8.00 # Remark: Performs math and formats to 2 decimal places. |
1 2 3 4 5 6 |
# Learn Python to A.I Programming - Robotronix.co.il , Yaniv Maor # Solution 5 – Format as currency price = 5.6789 print(f"Price: ${price:.2f}") # Output: Price: $5.68 # Remark: f-string with '$' symbol and 2 digits after decimal. |