Python Forum
Help with a random.randint choice in Python
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help with a random.randint choice in Python
#1
import random

#This program is being written for a close friend of mine and I need help with the choice program, I need it to choose a random letter out of the alphabet so that it can print on of the sentences below at random. Everything else works as it's supposed to, but i just can't get that one to work.

a = ("I Love you more than you could ever know and I hope you stay around for as long as you can. <3")
b = ("I wish I could give you a hug just to let you know how much you are loved, physical affection is the key to happiness.")
c = ("I love you so muchhhhhhhh *pinches your cheeks like a little old lady* AAAAHHHHH LLOOOK HOW CUTTTEEEE!!!")
d = ("*hugs you tightly* I'm sorry that you had a bad day..")
e = ("**Insert chummy quote I got off google**")
f = ("kissu kissu I would give you all the forehead kisses and the candy kisses I could aquire uwu")
g = ("XD pounces on you uwu you so warm~ (I'm sorry lmao)")
h = ("I want you to know something, but I don't know how to say it, so I'll let the first 3 words of this explain. *wink wonk*")
i = ("The only key to my heart is your smile, so I'd like to keep it around for a while. <3")
j = ("Get up, brush your hair (if you want), brush your teeth, take a shower, get dressed up, I'll be there in about.... 1052294 minuets. \n then I'll be able to give you a really big hug. <3")
k = ("Call me man, just call me, I wanna hear your voice as I make you laugh after we have a long talk about your day.")
l = ("I could sing for you, but it won't be very good. qwq")
m = ("How can I turn a virtual hug for more real...wait, this isn't google?")
n = ("uhhh... haha... I'M MELLLLlllltinggg (sorry, I didn't have an idea- ) ")
o = ("You and I are more than friends.........................................................................we're a small gang lmao, Wanna be the leader, we can bash some heads in COD while we have deep late night talks. ;-;")
p = ("I wish I could smile at you, give you a hug, pat your head, and tell you how much I love you...")
q = ("I'm honored that you like me, it's the biggest acheivement I've ever made, I love being friends with you. <3")
r = ("Imagine being a teenager, I swear, the world is crazy. Anyway, wanna play some minecraft, we could make fun of each other the etire time haha..ha..ha q-q")
s = ("Supercalifragilisticexpialidosiuos, imagine saying that 10 times fast *_*")
t = ("Love me, love me, oh how you love me, move me, move me, oh how you do me.. this song has been stuck in my head foreverrr :/ dang")
u = ("I hope you like this, it took quite a while for me to make. I made it just for you. <3")
v = ("Letter V...what could I put here? perhaps a list of words that start with V?? yeah uwu. Have fun with ths lsit of 310 words that start with V \n vacancyvacant vacantly vacate vacation vacationer vaccinate vaccination vaccine vacillate vacuum vacuum cleaner vacuum-packed vagina vaginal vagrant vague vaguely vagueness vain vainly valedictorian valentine Valentine's Day valet valiant valiantly valid validate validity valley valor valuable valuables value values valve vampire van vandal vandalism vandalize vanguard vanilla vanish vanishing vanity vanity plate vanquish vapor vaporize variability variable variance variant variation varied variety various variously varnish varsity vary vase vasectomy vast vastly vat vault VCR VD veal veer vegan vegetable vegetarian vegetation veggies vehement vehemently vehicle vehicular veil veiled vein Velcro velocity velour velvet velvety vendetta vending machine vendor veneer venerable venerate venereal disease venetian blind vengeance vengeful venison venom venomous vent ventilate ventilation ventilator ventriloquism ventriloquist venture venue Venus veranda verb verbal verbally verbatim verbose verdict verge verification verify veritable vermin vernacular versatile versatility verse version versus vertebra vertebrae vertical vertically vertigo verve very vessel vest vestibule vestige vet veteran veterinarian veterinary veto vex via viability viable viaduct vial vibes vibrant vibrate vibration vicarious vice vice president vice versa vicinity vicious vicious circle viciously victim victimization victimize victor victorious victory video videocassette video game videotape vie view viewer viewing viewpoint vigil vigilance vigilant vigilante vigor vigorous vigorously vile vilify villa village villager villain villainy vindicate vindication vindictive vine vinegar vineyard vintage vinyl viola violate violation violence violent violently violet violin violinist VIP viper viral virgin virginity Virgo virile virility virtual virtually virtual reality virtue virtuoso virtuous virulent virus visa visage vis-a-vis viscosity viscous vise visibility visible visibly vision visionary visit visitation visitor visor vista visual visual aid visualize visually vital vitality vitally vital statistics vitamin vivacious vivaciously vivacity vivid vividly vivisection V-neck vocabulary vocal vocalist vocation vocational vociferous vociferously vodka vogue voice voice mail void vol. volatile volatility volcanic volcano volition volley volleyball volt voltage volume voluminous voluntarily voluntary volunteer voluptuous vomit voodoo voracious voracity vortex vortices vote voter voting vouch voucher vow vowel voyage voyager voyeur voyeurism vs. vulgar vulgarity vulnerability vulnerable vulture ")
w = ("Oh god, I really hope you don't get letter V lmao, if you do, good luck <3 love youuuu")
x = ("I really hope you days are better soon, you deserve to have at least one nice day.")
y = ("Your one of my favorite people in the world, I hope you know that you'll always been in the top 10 <3")
z = ("I understand how you feel, 2020 has really come for everyone at every angle huh? It sucks, I really wish I could make you feel better than you do now.")

print("Hi! I really missed seeing you today </3")
print("I was wondering about how you were feeling.")
print("I remembered that you said that most day's you were feeling down...I was hoping maybe I could cheer you up maybe even a little with some jokes and stuff,,,;-;")
hru = input("How are you feeling today then..? ")
if(hru == "Good" or hru == "good" or hru == "great" or hru == "Great" or hru == "okay" or hru == "fine"):
print("I'm glad to hear that your day is going well, I hope it stays okay, just remember that I'm here for you <3")
else:
print(random.choice(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z))

#above is the choice option I tried most recently, I'm using Python coding and CodeSkulptor to write this code.
Reply
#2
put another pair of brackets around the choices
print(random.choice((a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z)))
booponion likes this post
Reply
#3
(Oct-23-2020, 03:39 PM)Yoriz Wrote: put another pair of brackets around the choices
print(random.choice((a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z)))

omg thank you, I feel really dumb now.
Reply
#4
You don't need parentheses around the string assignments.

I'd probably prefer to put the text into a container (like a list/dict/tuple) rather than into 26 top-level variables.

But the main problem is that random.choice takes a single sequence. You're feeding it 26 individual variables. Wrap them in another pair of parentheses to make a tuple and it should work.

print(random.choice((a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z))
booponion likes this post
Reply
#5
I'd do it a bit differently, based more around code like this
import random
options = list()
options.append('First entry')
options.append('Second entry')
options.append('third entry')
options.append('fourth entry')
print(options[random.randint(0,len(options)-1)])
That does not limit you to 26 choices, and would be more maintainable.
booponion likes this post
Reply
#6
I would put all the messages in a list, as you do, but without the intermediate step of assigning them to a variable first.
import random

messages = [
    "I Love you more than...",
    "I wish I could give you...",
    "I love you so muchhhhhhhh...",
    "I really hope you days are...",
    "Your one of my favorite people...",
    "I understand how you feel..."
]

print("Hi! I really missed seeing you today </3")
print("I was wondering about how you were feeling.")
print("I remembered that you said that most day's you were feeling down...I was hoping maybe I could cheer you up maybe even a little with some jokes and stuff,,,;-;")
hru = input("How are you feeling today then..? ")
if hru in ["Good", "good", "great", "Great", "okay", "fine"]:
    print("I'm glad to hear that your day is going well, I hope it stays okay, just remember that I'm here for you <3")
else:
    print(random.choice(messages))
Actually I think I would put the messages in a file so they could be easily changed.
with open('daily_affirmation.txt', 'r') as file:
    messages = file.readlines()
booponion likes this post
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  random numbers, randint janeik 2 526 Nov-27-2023, 05:17 PM
Last Post: janeik
  Unexpected output while using random.randint with def terickson2367 1 467 Oct-24-2023, 05:56 AM
Last Post: buran
  combobox_callback(choice choice part of openfile name (kind of dependency) janeik 9 1,345 Sep-10-2023, 10:27 PM
Last Post: janeik
Sad Iterate randint() multiple times when calling a function Jake123 2 1,979 Feb-15-2022, 10:56 PM
Last Post: deanhystad
  random.choice HELP samuelbachorik 4 2,219 Aug-18-2021, 03:24 PM
Last Post: naughtyCat
  Unable to use random.choice(list) in async method spacedog 4 3,353 Apr-29-2021, 04:08 PM
Last Post: spacedog
  Using Dictionary to Test Evenness of Distribution Generated by Randint Function new_coder_231013 6 3,198 Feb-23-2021, 01:29 PM
Last Post: new_coder_231013
  ???: if "{choice}" in self._command BaiYouLing4 3 1,967 Aug-23-2020, 05:40 AM
Last Post: BaiYouLing4
  trying to input a variable using random.choice python63 9 3,530 Aug-13-2020, 05:37 PM
Last Post: python63
  Random Choice Operations Souls99 6 2,889 Jul-31-2020, 10:37 PM
Last Post: Souls99

Forum Jump:

User Panel Messages

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