How to constantly generate random numbers inside for i in range loop

2024/10/5 14:59:30
import random
world_size=8
for i in range(world_size)chunk_type=random.randint(1,2)print(chunk_type)

 import randomclass chunk_type():chunk_type=random.randint(1,2)world_size=8for i in range(world_size):chunk_type()print(chunktype.chunktype)

both pieces of code don't work

I am trying to make a 2d game using Ursina. All has gone well until I made terrain. The looping of terrain works well but when I try to make the types of chunks random the radiant function only works once. How do I fix this? By The Way I am new to stack overflow so this would be a great help.

The above code should output should output a string of 8 random numbers between 1 and 2. I have tried update methods while true methods and the method for I in range. The radiant method only worked once so when I printed the variable for debugging it just reads all 1s or 2s. What can I do? There is no error messgae as the randiant function only works once.

Answer

If your only looking for integers you can do this.

import randomdef chunk_type():return random.randint(1,2)world_size=8for i in range(world_size):random_int = chunk_type()print(random_int)
https://en.xdnf.cn/q/119836.html

Related Q&A

How to count IDs that have a given combination of flags?

I have dataframe like that. I need to choose and count all distinct users, who have title "banner_click" and "order". So I dont understand how to do it in pandas, in SQL you do like…

How to calculate quarterly wise churn and retention rate using python

How to calculate quarterly wise churn and retention rate with date column using python. with date column i want to group that quarterly using python.This is used to calculate the churn count groupby qu…

splitting a list into two lists based on a unique value

I have a text file that looks something like this:hello 12 hello 56 world 25 world 26Is there a way in python that I can somehow parse the list that I obtain from reading this data to obtain two separa…

Customize axes in Matplotlib

I am a beginner with Python, Pandas and Matplotlib. I would like to customize the entries at the axes of a scatter plot. I have the following data:So on the x-axis there should be 5 entries, with the f…

how to show the max and min from user input?

Nevermindif xmin == 1:print(ymin)I tried using the max and min but I get a typeerror which is int object not iterable.

To output a string without whitespce

My program:def string_splosion(str):j=1c=len(str)i=0s=while(i<c):s=s+(str[:i+j])i=i+1print sprint("Enter a string:") s=raw_input() string_splosion(s)Sample input:Code Expected output:CCoCo…

Regex replace `a.b` to `a. b`? [duplicate]

This question already has answers here:Python: Replace with regex(2 answers)Closed 6 years ago.I am trying to change all strings of the type a.b to a. b. It should also work if any of the characters ar…

Is there something wrong with this line of Python code?

I tried this line of code, and it kept giving me the SyntaxError.print(/ / - / \ / | * 30, end=\r)^It pointed on the brackets. Any suggestions? Thanks!

TypeError: tuple indices must be integers or slices, not str postgres/python

Hi Im trying to get a timestamp from a row called time in my postgres database, however Im getting the error. Its the second row in the database. The error TypeError: tuple indices must be integers or …

Pandas Python: KeyError Date

I am import into python where it will automatically create a date time object.However I want the first column to be a datetime object in Python. Data looks likeDate,cost 41330.66667,100 41331.66667,101…