Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
SamBot
#1
I'm completely brand new to Python and I've been learning on a cool course. I will put what I learn into this project i'm working on named SamBot. It's a very simple bot that asks you questions and says it likes your answers. Here is the code, just put it into a Python editor and run it, that's all you need. This is the first version. (There is an Easter Egg so please don't read the code until you've found it):
# Program starts by giving credit to the author

import time

print("SamBot, simple chatbot written by: Benjamin Nation")

time.sleep(3)

# First Sam asks the user's name and says he likes it

print("Hi my name is SamBot!")

time.sleep(2)

userName = input("What's your name?")

time.sleep(1)

print("I love that name,", userName)

time.sleep(2)

# Then Sam asks what the user's favorite color is and responds that it's his favorite too

userColor = input("What's your favorite color?")

time.sleep(1)

print(userColor, "is my favorite color too!")

time.sleep(1)

# Sam then asks what their favorite movie is then responds saying he likes their movies and another movie
# out of a random list

import random

movieList = ["Harry Potter", "Hunger Games", "Onward", "Finding Nemo", "Ferngully", "Narnia"]

userMovie = input("What is your favorite movie?")

time.sleep(1)

print("I love", userMovie, "and", random.choice(movieList), "is really good too")

time.sleep(1)

# Now, Sam asks the user what their favorite game is, this process will be similar to the movies

gameList = ["Minecraft", "Fortnite", "Apex", "Gang Beasts", "Roblox", "Dauntless", "Untitled Goose Game"]

userGame = input("What is your favorite game?")

time.sleep(1)

print(userGame, "is a really good game but I like", random.choice(gameList), "better")

time.sleep(1)

# Sam will ask the user's age and then give it back in days

userAge = input("How old are you?")

time.sleep(3)

print("That's cool! Did you know you're also", int(userAge) * 365, "days old?")

time.sleep(3)

# Sam says his final goodbyes and asks if the user can speak with him again

print("I guess this is goodbye, will you try to talk to me again?")

goodbyeMessage = input("Y for yes and N for no")

if goodbyeMessage == "Y":
    time.sleep(1)
    print("Yay! See you soon!")
if goodbyeMessage == "N":
    time.sleep(5)
    print("Oh")
    time.sleep(5)
    print("Ok")
    time.sleep(5)
    print("Goodbye anyway")
if goodbyeMessage == ("Easter Egg 001"):
    time.sleep(1)
    print("You worked hard enough to find my first Easter Egg! Good job! See you soon!")

time.sleep(2)

print("Time to go!")

time.sleep(5)
Reply
#2
I would say you need to start formatting your strings as in
print("I love", userMovie, "and", random.choice(movieList), "is really good too")
You can just write
print(f"I love {userMovie}, and {random.choice(movieList)} is really good too")
What i did there is i put the "f" formatting before the string to enable me to call variables inside "{}" brackets, It's pretty simple stuff and saves allot of time plus looks better, Go here for a better explanation.
And the best practice is to put all of your imports at the top of the file instead.
Reply
#3
Well, it's a great interactive program but there is a problem surely,
So in the ' What is your favorite game' i typed Fortnite, and here's the output
Output:
Fortnite is a really good game but i like Fortnite better
So, maybe you can work on making sure the program doesn't repeat the name of the game...
And also, the same thing can happen in the movies
pyzyx3qwerty
"The greatest glory in living lies not in never falling, but in rising every time we fall." - Nelson Mandela
Need help on the forum? Visit help @ python forum
For learning more and more about python, visit Python docs
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020