Hey guys i create v1 of my bot code, feel free to update or upgrade it as you like x).
names = [“ben”, “benzo”, “benzoww”]
name = input("Who are you? ")
if name in names:
goal = input("What Dev language you want to learn? ")
scale = int(input("On a scale of 1 - 10, how do you feel today? "))
if goal in [“python”, “javascript”, “java”, “c++”, “c#”, “php”, “ruby”, “go”]:
print("Hey " + name + “, keep your chin up! You’re going to learn”, goal, “fast and efficiently. But remember, you need more than just”, goal, “to achieve your goals.”)
print()
if scale is not None and scale >= 1 and scale <= 10:
if scale == 1:
message = “You can do more than 1 though.”
elif scale == 2:
message = “You can do more than 2 though.”
elif scale == 3:
message = “You can do more than 3 though.”
elif scale == 4:
message = “You can do more than 4 though.”
elif scale == 5:
message = “You can do more than 5 though.”
elif scale == 6:
message = “You can do more than 6 though.”
elif scale == 7:
message = “You can do more than 7 though.”
elif scale == 8:
message = “You can do more than 8 though.”
elif scale == 9:
message = “You can do more than 9 though.”
else:
message = “You’re doing great! Keep it up!”
print(message)
elif scale is not None:
print(“Invalid scale rating.”)
Making your code DRY (Do Not Repeat Yourself) should be a goal.
names = ["ben", "benzo", "benzoww"]
name = input("Who are you? ")
if name in names:
goal = input("What Dev language you want to learn? ")
scale = int(input("On a scale of 1 - 10, how do you feel today? "))
else:
print("I'm sorry, I don't know you.")
goal = None
scale = None
if goal in ["python", "javascript", "java", "c++", "c#", "php", "ruby", "go"]:
print(f"Hey {name}, keep your chin up! You're going to learn {goal}, fast and efficiently. But remember, you need more than just {goal}, \"to achieve your goals.\"\n")
if scale is not None:
message = "Invalid scale rating."
if scale >= 1 and scale < 10:
message = f"You can do more than {scale} though."
elif scale == 10:
message = "You're doing great! Keep it up!"
print(message)
if scale == 1:
message = "You can do more than 1 though."
elif scale == 2:
message = "You can do more than 2 though."
elif scale == 3:
message = "You can do more than 3 though."
elif scale == 4:
message = "You can do more than 4 though."
elif scale == 5:
message = "You can do more than 5 though."
elif scale == 6:
message = "You can do more than 6 though."
elif scale == 7:
message = "You can do more than 7 though."
elif scale == 8:
message = "You can do more than 8 though."
elif scale == 9:
message = "You can do more than 9 though."
All but the number was same, so I wrote the following to not repeat all of the if/elif. It makes the code more concise and definitely helps readability.
if scale >= 1 and scale < 10:
message = f"You can do more than {scale} though."