exotic_weapons = ['Cerberus+1', 'Lumina', 'Monte Carlo', 'Riskrunner', 'Trinity Ghoul']
primary_weapons = ['Cerberus+1', 'Lumina', 'Monte Carlo', 'Battle Scar']
secondary_weapons = ['Come to Pass', 'Riskrunner', 'Heliocentric QSc', 'The Recluse', 'Trinity Ghoul']
heavy_weapons = ['Palmyra-B', 'Tarnation', 'Nasreddin', 'Edge Transit', 'Geodetic HSm', 'Royal Entry']
non_exotic_weapons = ['Battle Scar', 'Come to Pass', 'Heliocentric QSc', 'The Recluse', 'Palmyra-B', 'Tarnation', 'Nasreddin', 'Edge Transit', 'Geodetic HSm', 'Royal Entry']
import random
random.primary = random.choice(primary_weapons)
random.secondary = random.choice(secondary_weapons)
random.heavy = random.choice(heavy_weapons)
#can only use 1 exotic weapon in game but I don't know how to restrict the results to stop it from giving multiple exotic outputs
#results or outputs of randomizer
print("primary weapon is " +random.primary)
print("secondary weapon is " +random.secondary)
print("heavy weapon is " +random.heavy)
#only weapons right now, but I want to add armor and armor mods to the randomized outputs ```
#π I'm making a randomizer but I've only been using python for 3 days. anything I can improve or stud
47 messages Β· Page 1 of 1 (latest)
@spare kayak
Remember to:
- Ask your Python question, not if you can ask or if there's an expert who can help.
- Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
- Explain what you expect to happen and what actually happens.
:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.
Closes after a period of inactivity, or when you send !close.
looks pretty good actually
- imports should be at the top of the file:
import random
import time
# all your actual code goes here
- Instead of storing the random choices as
random.primaryorrandom.secondary, just useprimaryorsecondaryas the variable name
Also one way you could implement the exotic functionality is to pick a random exotic and then pick the remaining based on what type that exotic is. Something like:
exotic = random.choice(exotic_weapons)
primary_weapon = ''
secondary_weapon = ''
heavy_weapon = ''
if exotic in primary_weapons:
primary_weapon = exotic
# set the other two weapons
secondary_weapon = random.choice(secondary_weapons)
heavy_weapon = random.choice(heavy_weapons)
elif exotic in secondary_weapons:
secondary_weapon = exotic
...
else
heavy_weapon = exotic
...
Ok I've been asking chat gpt for most of my questions and it got me this far but I got stuck last night. Rewrote all the code 21 times. I knew what i wanted it to do but I didnt know how to write the code for it. This is going in my notebook. Many thanks stranger!
Thank you, that actually makes it so much easier. 
Mhm glad to help! Also, chatGPT usually isnβt a great source for info; Iβd definitely recommend trying to understand your code and researching on StackOverflow (or similar) when you have bugs. Happy coding!!
dont try asking chatgpt for help, it's not made to write code. its just made to generate text
it can write code, just not well
Yeah, I figured it wasn't helping when it kept giving me bad code. I also wasn't learning much from it besides having it "explain variables to me as if I were in elementary school." Which did help a lot.
Traceback (most recent call last):
File "main.py", line 3, in <module>
primary = random.primary
^^^^^^^^^^^^^^
AttributeError: module 'random' has no attribute 'primary' ```
Welp that didn't work. For the variable or the py thing lol
Yay fixed it
I meant do py primary = random.choice(primary_weapons) instead of ```
random.primary = random.choice(primary_weapons)
primary = random.primary
Ah
Oh yeah that's slick. πβοΈ
primary = random.choice(primary_weapons)
secondary = random.choice(secondary_weapons)
heavy = random.choice(heavy_weapons)
#can only use 1 exotic weapon in game but I don't know how to restrict the results to stop it from giving multiple exotic outputs
#results or outputs of randomizer
print("primary weapon is " +primary)
print("secondary weapon is " +secondary)
print("heavy weapon is " +heavy) ```
I am enlightened
many thanks
!fstrings
If you want to do some more studying for the next step, look at the below message from the bot.
Format-strings
Creating a Python string with your variables using the + operator can be difficult to write and read. F-strings (format-strings) make it easy to insert values into a string. If you put an f in front of the first quote, you can then put Python expressions between curly braces in the string.
>>> snake = "pythons"
>>> number = 21
>>> f"There are {number * 2} {snake} on the plane."
"There are 42 pythons on the plane."
Note that even when you include an expression that isn't a string, like number * 2, Python will convert it to a string for you.
when you do random.stuff = .... you are actually introducing an attribute to Python's random module :p
that's how dynamic the language is
use of "." is not allowed in identifiers (variable names), so we don't use it anyway
the random.choice and its friends are how we access what the random module supplies to us
"." is like a "possessive determiner" -- give me random*'s* choice etc.
Okay. So it's operators are symbols that tell the computer what to do, is '.' An operator then?
Im not sure if you can see it as an operator. More of a key"word". (I think)
(Like: for, while, if)
But maybe someone else will have the official terminology. π
I think how Nahita described it is pretty good and clear to follow.
random.choice means the choice that comes from the random module.
it is an operator, similar to how subscripting is an operator, you'll find it on the official operator precedence list as "attribute reference"
https://docs.python.org/3/reference/expressions.html#operator-precedence
i go by the rule of thumb that says: if it's not a label, and you can use it in an expression, then it's probably an operator - this is very much unlike operators as we know them in math though, so it's hard for me to wrap my head around them being in the same category
maybe the . on the left side of an assignment statement, where it points to an attribute to assign to, is not an operator, since that isn't an expression, but it is an operator when it's in an expression... bah
import random
primary_weapons = ['Cerberus+1', 'Lumina', 'Monte Carlo']
#non exotic primary, in case the chosen exotic is secondary/heavy
non_e_primary_weapons = ['Battle Scar']
secondary_weapons = ['Riskrunner', 'Trinity Ghoul']
#non exotic secondary, in case the chosen exotic is primary/heavy
non_e_secondary_weapons = ['Come to Pass', 'Heliocentric QSc', 'The Recluse']
heavy_weapons = ['Palmyra-B', 'Tarnation', 'Nasreddin', 'Edge Transit', 'Geodetic HSm', 'Royal Entry']
#non exotic heavy weapons,
non_e_heavy_weapons = ['Palmyra-B', 'Tarnation', 'Nasreddin', 'Edge Transit', 'Geodetic HSm', 'Royal Entry']
exotic_weapons = ['Cerberus+1', 'Lunina', 'Monte Carlo', 'Riskrunner', 'Trinity Ghoul']
#line 14 not needed?
non_exotic_weapons = ['Battle Scar', 'Come to Pass', 'Heliocentric QSc', 'The Recluse', 'Palmyra-B', 'Tarnation', 'Nasreddin', 'Edge Transit', 'Geodetic HSm', 'Royal Entry']
primary = random.choice(primary_weapons)
secondary = random.choice(secondary_weapons)
heavy = random.choice(heavy_weapons)
exotic = exotic_weapons
#can only use 1 exotic weapon in game but I don't know how to restrict the results to stop it from giving multiple exotic outputs
exotic = random.choice(exotic)
if exotic in primary_weapons:
primary_weapon = exotic
# set the other two weapons
secondary_weapon = random.choice(non_e_secondary_weapons)
heavy_weapon = random.choice(non_e_heavy_weapons)
elif exotic in secondary_weapons:
secondary_weapon = exotic
primary_weapon = random.choice(non_e_primary_weapons)
heavy_weapon = random.choice(non_e_heavy_weapons)
...
else:
heavy_weapon = exotic
primary = random.choice(non_e_primary_weapons)
secondary = random.choice(non_e_secondary_weapons)
...
#results or outputs of randomizer
print("primary weapon is " +primary)
print("secondary weapon is " +secondary)
print("heavy weapon is " +heavy) ```
Something is still acting goofy. 
Did you replace the ... with actual code when you run it?
Oh
primary weapon is Lumina (primary exotic)
secondary weapon is Trinity Ghoul (secondary exotic)
heavy weapon is Geodetic HSm ```
Still have more than one exotic output. 
It's kind of like a puzzle. This shit is cool af
you wrote in exotic_weapons "Lunina" instead of "Lumina" Maybe that's why

Fixed
I'm pretty sure something is funky with the else if statements. I'll be playing with those over the weekend.
I would do it differently. This If elif else block repeats too much
Looking for a way to make it much more simple. Trying to smooth it out is giving me an aneurysm.
a tip: use a loop
Ooo I'll give it a shot
This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.