Why does my list slice not return last 6 values in my problem

I am trying to return the last 6 values of a list but it doesn’t work right. I want it to return [1, 2, 2, 3, 5, 6] but it returns [0, 0, 2, 5, 6] and I can’t see why any help is appreciated. nums1 = [1,2,3,0,0,0] nums2 = [2,5,6] ans = nums1 +… Read More Why does my list slice not return last 6 values in my problem

Exception defined but shows undefined when raised in condition – Python

I have a custom exception defined but when I raise the error under a specific condition, I get to see "Exception not defined" error. Below is my code: #difference between 2 arrays. If this variable is not null then my custom exception should fire up tabs_diff = set(tabs_array) – set(tabs) #custom exceptions 2 class FileComponentMismatch(Exception):… Read More Exception defined but shows undefined when raised in condition – Python

How to use the result of a function call as condition of the loop and in the body of the loop?

The following concept works in the C and C++ languages, you assign the result of a function to a variable and then use the newly assigned variable as the condition for the while loop. So using the comma operator. A sample bit of C++ code looks like this. I’ve mocked the behavior of a function… Read More How to use the result of a function call as condition of the loop and in the body of the loop?

why these variables in def number 3 are not defined?

class Company: def __init__(self,name,age,salary,rating): self.Employee=name self.Employeeage =age self.Employeesalary =salary self.rating=rating def myfunc (self): if self.rating <= 2.5: print(‘BAD’) else: print(‘GOOD’) def sfunc (self): if self.age <= 60: #here age is not defined self.salary+=5000 #here salary is not defined print(f’salary is {self.salary}’) >Solution : You have asked why the variables in the method sfunc() (or "def… Read More why these variables in def number 3 are not defined?

How do I write code in order to generate random numbers in a way that a random number can only be printed once every 5 times

I’ve written code in python in order to generate random numbers between 110-115, 19 times. The code works however I would like to add code that states that the same random numbers cannot be printed out next to each other, they can only be printed out after the other 5 numbers have been used. for… Read More How do I write code in order to generate random numbers in a way that a random number can only be printed once every 5 times