r/learnpython • • 16h ago

Is it normal in an interview for an interviewer to ask very niche questions?

61 Upvotes

I recently had an interview for an intern position. my resume had some good Python projects and my previous internship experience also involved Python.

The interviewer began by asking me basic Python questions, which I answered well. He then moved on to more detailed questions.

Interviewer: What would be the output of the following code?


num1 = 1

num2 = 1

num3 = 257

num4 = 257

print(num1 is num2, num3 is num4)

I know about integer caching in python, so I said True, False. The interviewer asked if I was sure, and I said yes. He then handed me his laptop, opened VS Code, and asked me to run the code. To my horror, it printed True, True.

He moved on to the next question.

Interviewer: What is __init__ in Python?

Me: It’s a constructor for a class.

Interviewer: What is the first argument it takes?

Me: The object we created.

Interviewer: If it’s the constructor, how can it take the object itself? Who creates the object if __init__ is the constructor?

Me : Silence.

I know it's kinda my fault for this question.

Moved on to the next question

Interviewer: What is the output of the following code?


def fun(a=[], i=1):

    a.append(i)

    print(a)

fun()

fun(i=2)

I didn’t know that Python reuses the same list when it’s used as a default argument, so I got it wrong.

He moved on to the next question.

Interviewer: What is the output of this code?


tup = ([1, 2, 3], 4, 5)

try:

    tup[0] += [4, 5]

    print('tup modified', tup)

except:

    print('Not modified', tup)

Apparently it raises an error on the third line, but the list still gets modified. The output is:


Not modified ([1, 2, 3, 4, 5], 4, 5)

I haven’t heard back yet, but I’m wondering: is this how python specific interviews typically go?

How should I prepare for these kinds of scenarios next time?


r/learnpython • • 19h ago

The python library "Beautiful Soup", from where did it gets that name from?

33 Upvotes

√|


r/learnpython • • 7h ago

My first complete comand in Python, from my first day on:

18 Upvotes

Look:

import random
import time

def drawn(a, b):
    return random.randint(a, b)
answer = 'yes'

while answer == 'yes':
    a = int(input('Min number: '))
    b = int(input('Max number: '))
    print(f'Drawn: {drawn(a, b)}')

    time.sleep(2)

    answer = input('Try again? ').lower()

This creates a random number generator where you can choose the minimum and maximum numbers!


r/learnpython • • 12h ago

Python Dice Roller Help

3 Upvotes

Hello, I was making a sort of dice roller function that could be called to make a range of random numbers. However, I get an error and cant understand really what is wrong.

My Code to do this is:

import random


def diceroll(high, low, times):
    
    for _ in range(int(times)):
        random.randint(int(high), int(low)) 
    return high, low, times


high = input("enter a high number: ")
low  = input("enter a low number: ")
times = input("how many times would you want this to run? ")
drresult = diceroll(high=int(high), low=int(low), times=int(times))
print(drresult)import random


def diceroll(high, low, times):
    
    for _ in range(int(times)):
        random.randint(int(high), int(low)) 
    return high, low, times


high = input("enter a high number: ")
low  = input("enter a low number: ")
times = input("how many times would you want this to run? ")
drresult = diceroll(high=int(high), low=int(low), times=int(times))
print(drresult)

And the Error:

File "D:\PYTHONPROJECTS\EXERCISESANDTESTS\TEST0001\TESTAPP-0001.py", line 12, in <module>
    drresult = diceroll(high=int(high), low=int(low), times=int(times))
  File "D:\PYTHONPROJECTS\EXERCISESANDTESTS\TEST0001\TESTAPP-0001.py", line 6, in diceroll
    random.randint(int(high), int(low)) 
  File "C:\Users\Ryan Axtell\AppData\Local\Programs\Python\Python310\lib\random.py", line 370, in randint
    return self.randrange(a, b+1)
  File "C:\Users\-\AppData\Local\Programs\Python\Python310\lib\random.py", line 353, in randrange
    raise ValueError("empty range for randrange() (%d, %d, %d)" % (istart, istop, width))
ValueError: empty range for randrange() (20, 2, -18)

Any help would be appreciated!


r/learnpython • • 43m ago

Final project

1 Upvotes

Hi, so i have a final project in uni so im first year student and we take python on semester 1 and the prof made us choose whatever it just need to be in python only and each oneh as 5 functions

so me and my team picked lost and found system which we didnt know anything about it
so its includes a report a lost item part and report a found item part and search and match part and the file handling

i swear this stuff is harder than it seemed we dont take in uni how to make a project its like they threw us in the sea and told us learn to swim
and now i feel so overwhelmed there is alot of stuff that idek how to do
starting from how do we even start to how to work together and how does the program should look like

so i asked ai to give me a sample of what my part should look like which is the file handling and the search and match it gave some complicated stuff that i cant even understand and the project should be done in 4 weeks maybe less

so i wanted to ask how do i do the project without ai and actually understand what the actuall fuck is going on.


r/learnpython • • 1h ago

Sentence transformer model - what has worked for you in JIRA

1 Upvotes

Hi Red fam. I work in PMO and was looking at change management tickets logged in JIRA. Idea was to group tickets and take it up with LT for process interventions.

For context, my org is flexible in terms of who gets to raise JIRA tickets - be it Product, Architecture, Engineering, Delivery or Project Managers themselves (way of working fail). One objective was to find any correlation between groupings and job roles.

I used BERTopic for topic creation and mpnet for clustering. While am happy with the MVP - I had to brute force some business overrides/nuances as the model misgrouped quite a few tickets.

I tried changing dimensionality and clustering variables but the model didn’t help much beyond a point. Am looking for suggestions to train the model on existing data and automatically group new tickets that come in into the queue - can anyone please help me with an approach?


r/learnpython • • 12h ago

Help a beginner out with tuple unpacking :D

1 Upvotes

Yes I know its rather beginner, but since starting my python class I've been breezing through and its been so fun to learn, and I began to wonder why so many pythonists and other high level language users say its so hard.

Then I met tuple unpacking. I don't know what it is or why but its so hard for me to grasp and do. Here's an example problem I struggled with:

Q: analyze daily revenue based on the meals customers purchase

menu = {

"Burger": 12.50,

"Pizza": 15.00,

"Pasta": 13.50,

"Salad": 9.00,

"Sandwich": 8.50,

"Fries": 4.00

}

orders = [

("Monday", "Burger", 2), ---- These are Day, Product, Quantity btw

("Monday", "Pizza", 1),

("Tuesday", "Pasta", 3),

("Wednesday", "Burger", 1),

("Wednesday", "Fries", 4),

("Thursday", "Pizza", 2),

("Friday", "Sandwich", 2),

("Saturday", "Pasta", 2),

("Sunday", "Salad", 3)

]

Basically I'm supposed to get the price from the dictionary, and add to orders to get the daily revenue, such as like

Monday: 40.00
Tuesday: 40.5

and etc

But I keep messing up, I just can't seem to grasp the concept despite how much I have GPT give me more problems, the closest I got was this. One recurring issue I have is making sure a day doesn't repeat, like having Multiple Mondays when it should just be one monday and the final revenue for that day:

def calculate(sales):

daily_sales = {}

for day, product, quantity in orders:

price = menu[product]

daily_sales[day] = daily_sales.get(day, 0) + (price * quantity)

return(daily_sales)

print(orders)