Python Coding Interview Questions

Avatto > > DATA SCIENTIST > > SHORT QUESTIONS > > Python Coding Interview Questions

i = 2
while(i < 20):
j = 2
while(j i/j) :
print (i," is a prime number")
i = i + 1
list_example = ['Amit','Sumit','Rahul']
print(list_example)
list_example[1] = 'Kamal'
print(list_example)
['Amit', 'Sumit', 'Rahul']
['Amit', 'Kamal', 'Rahul']
def game_name(name):
for x in game_name
print(x)
example = [‘Cricket’,’Football’,’TT’]
game_name(example)
def pizza(size, *toppings):
  print("\nMaking a " + size + " pizza.")
  print("Toppings:")
  for topping in toppings:
     print("- " + topping)
# Make three pizzas with different toppings.
make_pizza('small', 'pepperoni')
make_pizza('large', 'bacon bits', 'pineapple')
make_pizza('medium', 'mushrooms', 'peppers', 'onions', 'extra cheese')
Splitting a dataset into a train and test is one of the initial stages of most of the machine learning models. Following is how you can split the dataset in python:-
from sklearn.model_selection import train_test_split
X_train,X_test,Y_train,Y_test = train_test_split(dataframe_name,target_variable,test_size=0.3, random_state=42)
dataframe_name = the complete dataset as a panda dataframe target_variable = the name of the target variable test_size = 0.3 denotes 70-30 split of the dataset in train and test random_state = 42, Look for the explanation in the next question