Skip to content

codeabode101/Robot-Logic-Python

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 

Repository files navigation

🤖 5-Day Python Project: My Robot Helper

Build and manage your own virtual robot assistant, giving it tasks and keeping it charged!


Day 1: Robot Introduction and Personality

Today, you'll bring your robot to life and give it a unique role!

  1. Create a new Python file named robot_manager.py.
  2. Ask for your robot's name. Use the input() function to get a name from the user and store it in a variable (e.g., robot_name).
  3. Ask for your robot's role. Use input() to ask "What kind of helper is [Robot Name]? (e.g., cleaner/friend/guard)" and store it in a variable (e.g., robot_role).
  4. Set your robot's starting battery_level to 100. Store this in another variable.
  5. Print a welcoming message using an f-string or string concatenation. It should include your robot's name, its role, and its current battery level.
    • Example Input: "Bolt", "cleaner"
    • Example Output: "Hello! I am Bolt, your new cleaner helper! My battery is 100%."

Day 2: First Task - Cleaning!

Your robot will perform its very first useful task!

  1. Define a function called perform_task(task_name, battery_cost, current_battery_level, robot_name).
    • This function needs to know the task_name, how much battery_cost it takes, the robot's current_battery_level (passed in as an argument), and the robot_name.
    • It should print() a message like "[Robot Name] is [task_name]."
    • It should then decrease the current_battery_level by the battery_cost.
    • Finally, it should print() the robot's updated current_battery_level and return the new battery level (so the main part of your program knows the updated value).
  2. Create a while True loop that will keep your robot active throughout the day.
  3. Inside the loop, ask the user: "What should [Robot Name] do? (clean/nothing/end_day)"
  4. Use if/elif statements:
    • If the user types "clean", call perform_task("cleaning the room", 10, battery_level, robot_name). Important: The value that perform_task returns will be the robot's new battery level, so make sure to update your battery_level variable with this returned value (e.g., battery_level = perform_task(...)).
    • If the user types "nothing", print a polite message like "Okay, resting for now."
    • If the user types "end_day", use break to exit the while loop.
  5. After the while loop finishes, print a message saying the day is over and show the robot's final battery_level.
    • Example Input: "clean"
    • Example Output: "Bolt is cleaning the room. Battery left: 90%"

Day 3: Recharge and New Tasks

Your robot needs more options and a way to refuel!

  1. Modify your while loop's question to include new options: "What should [Robot Name] do? (clean/wash dishes/charge/nothing/end_day)"
  2. Add a new task option: "wash dishes".
    • Modify your while loop's if/elif structure. If the user types "wash dishes", call perform_task("washing dishes", 15, battery_level, robot_name). Remember to update your battery_level variable with the returned value!
  3. Create a new function charge_robot(current_battery_level, robot_name):
    • This function should take the current_battery_level and robot_name as arguments.
    • It should increase the current_battery_level by 30.
    • Important: Make sure current_battery_level never goes above 100! Use an if statement to check and set it to 100 if the increase would push it higher.
    • Print a message like "[Robot Name] is charging. Battery increased to [level]%."
    • Return the new (updated) battery level.
  4. Add a new option in your while loop: "charge". If the user types "charge", call the charge_robot(battery_level, robot_name) function. Again, update your battery_level variable with the returned value.
  5. (Open-ended creativity): Add one more simple task of your own choice!
    • For example, "fetch item", "sing song", or "tell joke".
    • Decide how much battery_cost this new task will have (e.g., 5, 20).
    • Add this new option to your while loop's if/elif structure, calling perform_task and updating battery_level.
    • Example Input: "charge"
    • Example Output: "Bolt is charging. Battery increased to 100%."

Day 4: Battery Safety Check & Status

Robots need to be careful with their power! Let's make sure your robot doesn't try to do things without enough battery, and can tell you its status.

  1. Modify your perform_task function:
    • Before deducting battery: Add an if statement. If the current_battery_level is currently less than the battery_cost for the task:
      • print() a message like "[Robot Name] doesn't have enough battery for that task!"
      • Then, return current_battery_level. This is important because it stops the function and sends back the original battery level, showing that no change happened.
    • Only if there's enough battery should the rest of the function (deducting battery, printing new level, returning new level) happen.
  2. Modify your while loop's question to include a "status" option: "What should [Robot Name] do? (clean/wash dishes/charge/status/nothing/end_day)"
  3. Add a new command: "status"
    • In your while loop, add a new elif condition. If the user types "status":
      • print() a message like "Current battery: [battery_level]%."
      • This command should not change the battery_level, so you just print it; you don't need to call a function or update battery_level.
  4. (Open-ended creativity): Make your robot's output a bit more lively!
    • For example, when battery_level is low (e.g., below 20%), maybe it prints "[Robot Name] is feeling tired..." when you ask it to do something, or if battery is full, "[Robot Name] zips excitedly!" when it finishes charging.
    • This is just about adding extra print() messages based on battery level, not new variables. You'll add if statements in your existing perform_task or charge_robot functions, or directly in the while loop.

Day 5: Daily Report and New Interaction

Let's summarize the robot's day and add a unique touch!

  1. Introduce a new variable tasks_completed:
    • Initialize it to 0 at the very beginning of your script (before the while loop starts).
  2. Update tasks_completed:
    • Inside your while loop, for each task that calls perform_task:
      • You need to check if the task actually finished (meaning, if the battery went down).
      • Hint: Store the battery_level in a temporary variable before calling perform_task. Then, after calling perform_task and updating battery_level, compare the new battery_level to the old temporary one. If the new one is lower, it means a task was successfully completed, so you can increase tasks_completed by 1.
  3. Daily Report: At the end of your daily while loop (after "end_day"), print a simple summary of the day. For example:
    • "Today, [Robot Name] completed [tasks_completed] tasks. Final Battery: [battery_level]%."
  4. (Open-ended creativity): Add one more small, new interaction to your robot!
    • Option A: "greet" command: Add this as an option in your while loop. If the user types "greet", print a custom greeting like "Hello, Master!" or "Pleased to serve you!". This command should not cost battery.
    • Option B: "joke" command: Add this as an option. If the user types "joke", print a simple, pre-written joke. This command should not cost battery.
    • Or, invent your own unique small interaction! Think of a command that might print something fun or interact with the robot's state in a very small, simple way.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published