r/PythonLearning • • 1h ago

Hi, I'm learning python. Soooo I started yesterday and I'm a little bit cofusing. I'm brazilian, but the translations of some words are here.

Post image
12 Upvotes

I'm using VS code. I started trying to do a simple calculator (only with two numbers) for undestand the inical concepts and get familiarized with python. It's my first contact with coding. Ok what is my big problem: Up to line 3, everything is working fine and I understand it. Now, I'm trying to build a calculator where the user chooses how many numbers they want to calculate. The prompt repeats based on the number of factors they entered, using for i in range(quantidade_de_fatores - 1), and I created a list that keeps appending each new number the user inputs.

Depending on the operation chosen (addition, subtraction, multiplication, or division), it should calculate all the numbers in that list:

Addition (soma): I already have sum() working to add all the values in the list.

Multiplication (multiplicação): I tried using math.prod() to multiply everything in the list, though it's showing an error.

Division (divisão) and Subtraction (subtração): I don't know what function or logic to use to calculate all the numbers in the list one after another.

I already understand the final part that displays the result. My main problem is figuring out how to properly calculate all the stored numbers in the list for subtraction, division, and multiplication.

print ("Welcome to the calculator user")

name = input ("What should I call you?")

print (f"Hello " + name)

number_of_factors = int (input (f"How many numbers does {name} want to calculate with? "))

operation = input (f"Which operation does {name} want to perform?").strip().lower()

requested_factor = float ( input ("Enter a number."))

factors_list = [requested_factor]

for i in range (number_of_factors - 1 ):

next_requested_factors = float ( input ("Enter another number."))

factors_list.append (next_requested_factors)

if operation == "addition":

result = sum(factors_list)

result = requested_factor + next_requested_factors

if operation == "division":

result = requested_factor / next_requested_factors

if operation == "subtraction":

result = num1-num2

if operation == "multiplication":

result = num1*num2

answer = input ("Show result?").strip().lower()

if answer == "yes":

print (f"{result}" )

if result==67:

print ("SIX SEVEN")

if result==39:

print ("It's Miku time!!!!!")


r/PythonLearning • • 18h ago

Terminal Based Turn Based RPG beginner project

17 Upvotes

Very new to python. This is my first semi-large project.

In the video above, I show the admittedly amateurish code, and a demonstration. I demonstrate the WARRIOR and MAGE class to show basic and magic abilities in action.

A text based turn based RPG game which runs in the terminal. Commands like attack or defend must be typed manually and as they are displayed in the GUI to avoid type errors. So far there are 4 classes(one of the classes is not functional at the moment) with the ability to create a custom class. When creating a custom class the player gets 26 skill points to distribute across the different skills.

Skills include: Strength, Defense, Evasion, Critical Hit Damage, Agility, Spirit, Mana, Luck. The flow of the game is largely determined by these skills with some RNG mixed in.

Spells and Abilities are assigned to the player at the start of the game depending on the stats selected. Magic focused characters are assigned magic abilities while, damage/agility focused characters are assigned normal abilities. For magic assignment, the change of obtaining any particular skill is determined by the value of [(0.0-0.9)*Player spirit stat)] + a base obtain value. Ability assignment works in the same way but used the players ability stat to determine obtain chance.

Evasion skill determines the chance the player will dodge an enemy attack. Both the player and enemy have this skill.

An enemy is generated in the beginning game with the players stats in mind. This is done to ensure fairness.

To determine the value of the enemy attack value, I created a formula to dynamically assign a value based on the disparity between the player and enemy health stat. The equation is as follows...

A = \sqrt{100-[(\frac{P}{M}})\cdot 100]

or...

C = (Player_Health/Monster_Health) * 100

B = 100 - C

A = sqrt(B)

There is no party system in this game, which limits strategy. The enemy turn functions through an AI which is still a work in progress. I say AI, but no neural network is used, instead, the enemy learns which actions will yield positive results based on the player follow up action. The probability of an action being repeated is increased or decreased based on how detrimental/beneficial that follow up is.

No AI was used to create this. Again, I am a very amateur programmer and understand that there lots of things i can do to improve this, like utilizing object oriented programming, or less dependence on global variables, .json files, naming consistency like: statsPlayer, Player_Stats, stats. Please give suggestions of ideas for what I should add. I am actively learning while making this project and implemented a lot of these things would require to me to rewrite everything. I would rather finish what I have and create a new and improved version with these fixes.

Please give your feedback and ideas for what I should add. Currently I am in the process of completed the Magic buff and Ability buff system as not all buffs currently work, finishing the ITEM system, finishing enemy AI(as of now, all the enemy can do is use light attacks and dodge), adding a dungeon mode alongside current single mode, and adding a shop to buy items after obtaining gold in dungeon mode.

Dungeon mode would allow you to collect XP and level up as you defeat enemies, forcing you to fight stronger enemies as you grow stronger, until you reach a dungeon boss which uses unorthodox mechanics which the player will have to figure out to win. The player will be rewarded gold after each victory which can then be used at the shop.

Some additional notes: When creating your own class, naming your character "DEBUG" will enter you into debug mode, which allows you to change the LUCK stat to artificially increase RNG values. Otherwise, the LUCK stat is assigned a value randomly. When on battle menu, typing help will give a brief overview of the GUI and how to navigate it. When on the abilities screen, typing the ability name followed by the "--d" or "--description" tag will show the description of selected ability.

as of now only the "--d" tag is available, but I want to program in different tags for debug and quality of life purposes. Any ideas on what kinds of tags I should include?


r/PythonLearning • • 18h ago

Online classes for US teen?

10 Upvotes

My 13 year old wants to learn python next. Are there any online classes you all recommend?


r/PythonLearning • • 23h ago

Teammates in learning

2 Upvotes

Hey, I'm learning python for like a month. Just wondering if anyone could join me to make some projects together not super completed things.