Appearance
question:Write a script in Python that will generate multiplication tables from 1 to 10. Not applicable
answer:# Generate multiplication tables from 1 to 10 # Define function, which takes a single number as input def multiplication_table(number): # Initialize list for storing results results = [] # Iterate from 1 to 10 for i in range(1, 11): # Compute result result = number*i # Append result to list of results results.append(result) # Return list of results return results # Iterate from 1 to 10 for i in range(1, 11): # Compute multiplication table table = multiplication_table(i) # Print multiplication table print(f'{i} x {table}')
question:Write a Python program that stores the months of the year in a dictionary.
answer:months_dict = { 'January': 1, 'February': 2, 'March': 3, 'April': 4, 'May': 5, 'June': 6, 'July': 7, 'August': 8, 'September': 9, 'October': 10, 'November': 11, 'December': 12 }
question:Create a Python program that uses a sentiment analysis library like TextBlob to analyze reviews provided as input and classify each review as either positive or negative. The product is good quality and well made.
answer:import textblob review = "The product is good quality and well made." testimonial = textblob.TextBlob(review) sentiment = testimonial.sentiment.polarity if sentiment > 0: print("Review is positive.") elif sentiment == 0: print("Review is neutral.") else: print("Review is negative.")
question:Create a Selenium test automation script in Python for verifying a user login. Not applicable
answer:from selenium import webdriver from selenium.webdriver.common.by import By from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.support import expected_conditions as EC driver = webdriver.Chrome() driver.get('https://www.example.com/login') username_field = driver.find_element_by_name('username') password_field = driver.find_element_by_name('password') username_field.send_keys('example_username') password_field.send_keys('example_password') driver.find_element_by_xpath("//button[text()='Log in']").click() WebDriverWait(driver, 10).until_not(EC.url_changes('https://www.example.com/login')) assert driver.current_url == 'https://www.example.com/home'