[Solved] My Python code is looping at the wrong place

its easy to get confused when you have a big chunk of code like this … instead try and split your problem into smaller parts start with a function to get the details of only one student def get_student_detail(num_tests): # get the detail for just 1 student! student_name = input(“Enter Student Name:”) scores = [] … Read more

[Solved] Python, def_init_(self): syntax error

Instead of def_init_(self,name,age) You should use def __init__(self,name,age): def means you start a function (definition), and it needs a space to follow. The function __init__ is the constructor. There should always be a colon at the end of a function definition (followed by the body of the function). 0 solved Python, def_init_(self): syntax error

[Solved] Regular expression for date shown as YYYY

The “basic” regex matching just the year field is \d{4} but it is not enough. We must prohibit that before the year occurs: 3 letters (month) and a space, then 2 digits (day) and a space. This can be achieved with negative lookbehind: (?<!\w{3} \d{2} ) But note that: after the day field there can … Read more

[Solved] Clarification needed regarding immutability of strings in Python [closed]

In CPython, ids relate to where in memory the string is stored. It does not indicate anything about mutability. How memory is used exactly is an internal implementation detail. You could of course do a deep dive into the internals of CPython’s memory management to disentangle that in-depth, but that’s not really useful. (Im)mutability can … Read more

[Solved] strftime(“%A”) output is string. but assigning variable is expecting Int [closed]

There’s two issues. First, to get the day of the month, you should use %d, not %A with strftime(). date = time.strftime(“%d”); Second, this returns the day as a string, not as an integer, but datetime.date() requires its arguments to be integers, so you need to convert it with int(date) date = int(time.strftime(“%d”)) But there’s … Read more

[Solved] Fix a function returning duplicates over time?

@Martijn’s solution is enough since you only need to store and shuffle 9000 numbers. If you want numbers from a bigger range and you know (approximately) how many numbers you’ll need, there’s a better way: The function random.sample will give you numbers in the desired range without repetition. For example, to get 500 distinct six-digit … Read more