Day 025 - Project 25 : Character stats generator

If you have any questions, comments or issues with this project please post them here!

I’m on Day 25 and lesson 228. Toward the end of the lesson, import pandas, Create a dataframe from scratch . when the instructor runs the program it comes out ok but when I run it I get an error.

ValueError: All arrays must be of the same length.
import pandas

# Create a dataframe from scratch.
import pandas

data_dict = {
    "students": ["Amy", "James", "Angela"],
    "scores": ["76, 56, 65"]
} 
data = pandas.DataFrame(data_dict)
print(data)

:slightly_smiling_face:

Is Replit 101 a good platform to go to ask questions being that is seems to be relatively new?
:slightly_smiling_face:

Yes, @QZapper. That is an excellent place to go for live support.

1 Like

Thank you @BrittanyatReplit. What about my ‘DataFrame from scratch question?’ I’ve noticed a lot of questions on askreplit that others have posted with copies of their code questions. i’m new at posting. Was my format incorrect and if so how should I be submitting copies of code? :thinking:

You can format code with ``` I did it for you this time so don’t worry about it. Some more info is in this guide. Unfortenly I don’t know pandas so I cant assist you.

You can also create an invite link and share the link here so other users can look at your code directly to help you out.

Hey All

New here and first question re the Day25 lesson. I’m familiar with subroutines and passing/returning variables. But I do admit I’m struggling a bit with how Python does “sub” things.

First, the example uses the same variable “area” both inside and outside the subroutine. This seems bad coding practice and a recipe for disaster if someone else is trying to interpret your code. I was taught to never do this, so I don’t. I might use the variable “area_s” inside the sub, and “area” outside, for example.
Is it common practice among Python coders to use the same variable inside/outside the sub? Do I need to change my outlook on this?

Second, I am used to having a substantial main program, followed by subroutines. In the example, the main program consists of a line or two at the end of the sub, and the meat of the code is the sub located at the top. Can I switch the order, and have the main program first and the sub second?

Thanks!

1 Like

Hi @QZapper thanks for your question.

I think the issue is with the following line of code:

    "scores": ["76, 56, 65"]

You need to remove the quotes before the number 76 and after the number 65 as below:

    "scores": [76, 56, 65]

The program then works correctly. I’ve made a copy here for reference https://replit.com/@IanAtReplit/Day25#main.py

1 Like

Hi @chartanalyst welcome to the community and thanks for your question!

I teach and have been a programmer for a while. I understand why you name your variables differently inside and outside of the subroutine to help recognise local and global variables however I’d argue it is personal preference. In some high school / college courses you would submit your program alongside a document with a variable table and perhaps even a data flow diagram too.

In answer to your second question I’ve always been taught and have taught to have subroutines at the top and main program at the end of the code. However if it works for you to reverse this to complete the 100daysofcode challenges then I would suggest you go for it!

Hope you are enjoying the challenges and keep posting to the community!

Hey @IanAtCSTeach , thank you so much for that correction. I am a rookie so I guess I shouldn’t fell as bad as I do for not catching that clumsy error. I swore I looked at everything. Thank you. :+1:

1 Like

Hi @QZapper never a problem! Thanks for the thanks but we keep learning all the time. 39 years programming and still make the odd mistake that takes me a while to see!

Built a character health stats generator to prepare for the epic battle in 3 days!!

https://replit.com/@JackAdem/Day-025-Project-25-Character-stats-generator?v=1

Day 25 of #Replit100DaysOfCode #100DaysOfCode.

Ngl, it took me too much time and I was so stuck but finally I made through

1 Like

Hi,

For this challenge, the solution contains this line of code health = str(roll_6_and_8()).
I can’t really understand the purpose of using str, it seems the code works perfectly without str too.

str( ) converts whatever data in the parentheses into a string.

1 Like

Probably there is an implicit string conversion somewhere as with a + or a print.

1 Like