Python Answers

Questions answered by Experts: 5 288

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Search

Alternate numbers pattern using while loop write a python program how to use the while loop to print the number pattern.
Inverted pyramid pattern of numbers
An inverted pyramid is a downward pattern where numbers get reduced in each iteration, and on the last row, it shows only one number. Use reverse for loop to print this pattern.
How to fetch a data entry from a pandas dataframe using a given value in index?
To fetch a row from dataframe given index x, we can use loc.

Df.loc[10] where 10 is the value of the index.

Code

import pandas as pd
bikes=["bajaj","tvs","herohonda","kawasaki","bmw"]
cars=["lamborghini","masserati","ferrari","hyundai","ford"]
d={"cars":cars,"bikes":bikes}
df=pd.DataFrame(d)
a=[10,20,30,40,50]
df.index=a
How to fetch a data entry from a pandas dataframe using a given value in index?
To fetch a row from dataframe given index x, we can use loc.

Df.loc[10] where 10 is the value of the index.
Find out the mean, median and standard deviation of this numpy array -> np.array([1,5,3,100,4,48])
How to create a new column in pandas by using values from other columns?
We can perform column based mathematical operations on a pandas dataframe. Pandas columns containing numeric values can be operated upon by operators.

Code

import pandas as pd
a=[1,2,3]
b=[2,3,5]
d={"col1":a,"col2":b}
df=pd.DataFrame(d)
df["Sum"]=df["col1"]+df["col2"]
df["Difference"]=df["col1"]-df["col2"]
How to create a new column in pandas by using values from other columns?
We can perform column based mathematical operations on a pandas dataframe. Pandas columns containing numeric values can be operated upon by operators.

This problem is related to the virtual learning environment application discussed in one theory session and a few practicals. In this problem, you are tasked with creating and updating learner profiles, a particular type of user. As well, given a learner profile, we would like to retrieve the learning materials in the form of topics. Note that the learning materials for a given course will differ from one learner profile to another. For example, for a course "Distributed Systems and Applications", the learning materials for a learner with a weak background in "Programming" compared o another learner profile with a stronger background in programming.

Your task is to:

1. Provide a description in OpenAPI of the API that allows for communication between a client and a service for the functionalities discussed above;

2. Implement a corresponding client and a service. 


  1. A palindrome is a word or a phrase that reads the same way backwards as forwards. Write a function that accepts a text string as input and determines whether or not the text string is a palindrome. Then write a program that uses this function. Prompt the user to enter a word or phrase and then inform the user whether or not the text entered qualifies as a palindrome. [Hint: there is a REVERSE method for a string. But to compare an string reversed this way, you need to convert to list: if list(str) == list(rev_str):]

Given an integer between 0 and 10000, write a program to print the sum of its digits.Input


The first line of input will contain an integer.Output


The first line of output should be the sum of the digits.Explanation


For example, if the given number is 25, your code should print the sum of the digits (2 + 5), which is 7.


Similarly, if the given number is 692, your code should print the sum of the digits (6 + 9 + 2), which is 17.


Similarly, if the given number is 9999, your code should print the sum of the digits (9 + 9 + 9 + 9), which is 36.

Sample Input 1

25

Sample Output 1

7

Sample Input 2

692

Sample Output 2

17

Sample Input 3

9999

Sample Output 3

36



Python 3.9


RESET




Write a program for Horizon Phones, a provider of cellular phone service. Prompt a user for maximum monthly values for talk minutes used, text messages sent, and gigabytes of data used, and then recommend the best plan for the customer's needs. A customer who needs fewer than 500 minutes of talk and no text or data should accept Plan A at $49 per month. A customer who needs fewer than 500 minutes of talk and any text messages should accept Plan B at $55 per month. A customer who needs 500 or more minutes of talk and no data should accept either Plan C for up to 100 text messages at $61 per month or Plan D for 100 text messages or more at $70 per month. A customer who needs any data should accept Plan E for up to 2 gigabytes at $79 or Plan F for 2 gigabytes or more at $87.



#Loop through the prices in levelsList.
#During each loop:
#-Create a variable called priceLevelLabel consisting of the text 'Price Level: 'followed
# by the price.
#-Add priceLevelLabel and the price as two separate items to a new list (the sub-List).
#-Append the sub-List to displayList.
for price in self.levelsList:
LATEST TUTORIALS
APPROVED BY CLIENTS