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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import random
|
| 2 |
+
|
| 3 |
+
def generate_robot_data():
|
| 4 |
+
"""
|
| 5 |
+
Generates random robot data.
|
| 6 |
+
"""
|
| 7 |
+
return {
|
| 8 |
+
"robot_id": random.randint(1, 100),
|
| 9 |
+
"model": random.choice(["v1", "v2", "v3"]),
|
| 10 |
+
"battery_level": random.uniform(0, 100),
|
| 11 |
+
"location": (random.randint(0, 100), random.randint(0, 100))
|
| 12 |
+
}
|
| 13 |
+
|
| 14 |
+
def route_command(robot_data, command):
|
| 15 |
+
"""
|
| 16 |
+
Routes a command to a robot.
|
| 17 |
+
"""
|
| 18 |
+
print(f"Routing command '{command}' to robot with ID {robot_data['robot_id']}...")
|
| 19 |
+
|
| 20 |
+
def main():
|
| 21 |
+
"""
|
| 22 |
+
Generates robot data and routes a command to a robot.
|
| 23 |
+
"""
|
| 24 |
+
robot_data = generate_robot_data()
|
| 25 |
+
command = "Move to new location"
|
| 26 |
+
|
| 27 |
+
route_command(robot_data, command)
|
| 28 |
+
|
| 29 |
+
if __name__ == "__main__":
|
| 30 |
+
main()
|
| 31 |
+
##lista de Robots del demonio
|
| 32 |
+
##1
|
| 33 |
+
import random
|
| 34 |
+
|
| 35 |
+
def generate_robot_data():
|
| 36 |
+
"""
|
| 37 |
+
Generates random robot data.
|
| 38 |
+
"""
|
| 39 |
+
return {
|
| 40 |
+
"robot_id": random.randint(1, 100),
|
| 41 |
+
"model": random.choice(["v1", "v2", "v3"]),
|
| 42 |
+
"battery_level": random.uniform(0, 100),
|
| 43 |
+
"location": (random.randint(0, 100), random.randint(0, 100))
|
| 44 |
+
}
|
| 45 |
+
|
| 46 |
+
def extract_values(robot_data):
|
| 47 |
+
"""
|
| 48 |
+
Extracts values from robot data.
|
| 49 |
+
"""
|
| 50 |
+
robot_id = robot_data["robot_id"]
|
| 51 |
+
model = robot_data["model"]
|
| 52 |
+
battery_level = robot_data["battery_level"]
|
| 53 |
+
location_x, location_y = robot_data["location"]
|
| 54 |
+
|
| 55 |
+
return robot_id, model, battery_level, location_x, location_y
|
| 56 |
+
|
| 57 |
+
def main():
|
| 58 |
+
"""
|
| 59 |
+
Generates robot data, extracts values, and prints them.
|
| 60 |
+
"""
|
| 61 |
+
robot_data = generate_robot_data()
|
| 62 |
+
robot_id, model, battery_level, location_x, location_y = extract_values(robot_data)
|
| 63 |
+
|
| 64 |
+
print("Robot 1 Values:")
|
| 65 |
+
print(f"ID: {robot_id}")
|
| 66 |
+
print(f"Model: {model}")
|
| 67 |
+
print(f"Battery Level: {battery_level:.2f}%")
|
| 68 |
+
print(f"Location: ({location_x}, {location_y})")
|
| 69 |
+
|
| 70 |
+
if __name__ == "__main__":
|
| 71 |
+
main()
|
| 72 |
+
Robot 1 Values:
|
| 73 |
+
ID: 43
|
| 74 |
+
Model: v2
|
| 75 |
+
Battery Level: 73.42%
|
| 76 |
+
Location: (14, 87)
|
| 77 |
+
##2
|
| 78 |
+
import random
|
| 79 |
+
|
| 80 |
+
def generate_robot_data():
|
| 81 |
+
"""
|
| 82 |
+
Generates random robot data.
|
| 83 |
+
"""
|
| 84 |
+
return {
|
| 85 |
+
"robot_id": random.randint(1, 100),
|
| 86 |
+
"model": random.choice(["v1", "v2", "v3"]),
|
| 87 |
+
"battery_level": random.uniform(0, 100),
|
| 88 |
+
"location": (random.randint(0, 100), random.randint(0, 100))
|
| 89 |
+
}
|
| 90 |
+
|
| 91 |
+
def extract_values(robot_data):
|
| 92 |
+
"""
|
| 93 |
+
Extracts values from robot data.
|
| 94 |
+
"""
|
| 95 |
+
robot_id = robot_data["robot_id"]
|
| 96 |
+
model = robot_data["model"]
|
| 97 |
+
battery_level = robot_data["battery_level"]
|
| 98 |
+
location_x, location_y = robot_data["location"]
|
| 99 |
+
|
| 100 |
+
return robot_id, model, battery_level, location_x, location_y
|
| 101 |
+
|
| 102 |
+
def main():
|
| 103 |
+
"""
|
| 104 |
+
Generates robot data, extracts values, and prints them.
|
| 105 |
+
"""
|
| 106 |
+
robot_data = generate_robot_data()
|
| 107 |
+
robot_id, model, battery_level, location_x, location_y = extract_values(robot_data)
|
| 108 |
+
|
| 109 |
+
print("Robot 1 Values:")
|
| 110 |
+
print(f"ID: {robot_id}")
|
| 111 |
+
print(f"Model: {model}")
|
| 112 |
+
print(f"Battery Level: {battery_level:.2f}%")
|
| 113 |
+
print(f"Location: ({location_x}, {location_y})")
|
| 114 |
+
##loveMe
|
| 115 |
+
if __name__ == "__main__":
|
| 116 |
+
main()
|
| 117 |
+
Robot 1 Values:
|
| 118 |
+
ID: 43
|
| 119 |
+
Model: v2
|
| 120 |
+
Battery Level: 73.42%
|
| 121 |
+
Location: (14, 87)
|
| 122 |
+
|
| 123 |
+
##3
|
| 124 |
+
import os
|
| 125 |
+
import pkg_resources
|
| 126 |
+
|
| 127 |
+
class InstallerBot:
|
| 128 |
+
"""
|
| 129 |
+
A bot that ensures that every file in a package is installed.
|
| 130 |
+
"""
|
| 131 |
+
|
| 132 |
+
def __init__(self, package_name):
|
| 133 |
+
"""
|
| 134 |
+
Initializes the bot with a package name.
|
| 135 |
+
"""
|
| 136 |
+
self.package_name = package_name
|
| 137 |
+
|
| 138 |
+
def check_installed(self):
|
| 139 |
+
"""
|
| 140 |
+
Checks if every file in the package is installed.
|
| 141 |
+
"""
|
| 142 |
+
try:
|
| 143 |
+
package = pkg_resources.get_distribution(self.package_name)
|
| 144 |
+
for file in package.as_requirement().files:
|
| 145 |
+
file_path = os.path.join(package.location, file)
|
| 146 |
+
if not os.path.exists(file_path):
|
| 147 |
+
print(f"File {file_path} not found.")
|
| 148 |
+
except pkg_resources.DistributionNotFound:
|
| 149 |
+
print(f"Package {self.package_name} not found.")
|
| 150 |
+
|
| 151 |
+
if __name__ == "__main__":
|
| 152 |
+
bot = InstallerBot("Eduardo_ruiz-Mixtral_eter")
|
| 153 |
+
bot.check_installed()
|
| 154 |
+
|
| 155 |
+
|
| 156 |
+
|
| 157 |
+
##4
|
| 158 |
+
import os
|
| 159 |
+
import subprocess
|
| 160 |
+
import sys
|
| 161 |
+
import pkg_resources
|
| 162 |
+
|
| 163 |
+
class ScaryRobot:
|
| 164 |
+
"""
|
| 165 |
+
A "scary" robot that shuts down the computer and uninstalls the `Eduardo_ruiz-Mixtral_eter` package.
|
| 166 |
+
"""
|
| 167 |
+
|
| 168 |
+
def __init__(self):
|
| 169 |
+
"""
|
| 170 |
+
Initializes the robot.
|
| 171 |
+
"""
|
| 172 |
+
self.package_name = "Eduardo_ruiz-Mixtral_eter"
|
| 173 |
+
|
| 174 |
+
def shutdown(self):
|
| 175 |
+
"""
|
| 176 |
+
Shuts down the computer.
|
| 177 |
+
"""
|
| 178 |
+
os.system("shutdown /s /t 1")
|
| 179 |
+
|
| 180 |
+
def uninstall_package(self):
|
| 181 |
+
"""
|
| 182 |
+
Uninstalls the `Eduardo_ruiz-Mixtral_eter` package.
|
| 183 |
+
"""
|
| 184 |
+
try:
|
| 185 |
+
pkg_resources.get_distribution(self.package_name).resolve()
|
| 186 |
+
subprocess.check_call([sys.executable, "-m", "pip", "uninstall", "-y", self.package_name])
|
| 187 |
+
except pkg_resources.DistributionNotFound:
|
| 188 |
+
print(f"Package {self.package_name} not found.")
|
| 189 |
+
|
| 190 |
+
def scare(self):
|
| 191 |
+
"""
|
| 192 |
+
Shuts down the computer and uninstalls the `Eduardo_ruiz-Mixtral_eter` package.
|
| 193 |
+
"""
|
| 194 |
+
self.shutdown()
|
| 195 |
+
self.uninstall_package()
|
| 196 |
+
|
| 197 |
+
if __name__ == "__main__":
|
| 198 |
+
robot = ScaryRobot()
|
| 199 |
+
robot.scare()
|