A String variable named sentence that has been initialized, write an expression whose value is the number of characters in the String referred to by sentence. Python: sentence = “this is the sentence.” size = lens (sentence), C++: string sentence = “this is the sentence.” int size = sentence.
Python is an programming language with the integration of dynamic semantics for web and app development, extremely attractive in the field of Rapid Application Development.
Python is simple in comparison to other language program, so it’s easy to learn and understand well; it needs a unique syntax which is mainly focus on readability.
Developers can read and translate Python code in a easy way, than other languages and reduces the cost of program maintenance and development.
For more details regarding python, here
#SPJ2
instructions:
You need to write code that will print two bricks of numbers, one with integers, one with decimals.
import random
i = 1
while i <= 100:
print("#"+str(i)+": "+str(random.randint(1,100)), end=", ")
i+=1
print()
i = 1
while i <= 100:
print("#"+str(i)+": "+str(random.uniform(1,100)), end=", ")
i += 1
I hope this helps!
Answer:
The SI unit of energy rate
Explanation:
is the watt, which is a joule per second. Thus, one joule is one watt-second, and 3600 joules equal one watt-hour.
The program is a sequential program; as such, it does not require loops or conditional statements.
The program in Python, where comments are used to explain each line is as follows:
#This gets input for the cost of the meal
cost = float(input("Cost: "))
#This initializes the local rate tax to 7.25%
local_rate_tax = 0.0725
#This initializes the tip to 18%
tip = 0.18
#This calculates the tax amount
taxAmount = cost * local_rate_tax
#This calculates the tip amount
tipAmount = cost * tip
#This calculates the grand total
grand = cost + taxAmount + tipAmount
#This prints the tax amount
print("Tax amount: {:.2f}".format(taxAmount))
#This prints the tip amount
print("Tip: {:.2f}".format(tipAmount))
#This prints the grand total
print("Grand total: {:.2f}".format(grand))
All outputs are formatted to 2 decimal places.
See attachment for sample run
Read more about similar programs at:
Answer:
Explanation
If I were calculating a tip at a restaurant using the same syntax, it would have been. meal ... New value of meal is double meal times tax. you're saying: (meal + meal) * tax but meal + meal * tax is calculated in the following order meal + (meal * tax) ... eh? ;) The exercise implied it was just reading the equation from right to left.
Answer:discrimination
Explanation:
Answer:
The height of the ball after t seconds is h + vt - 16t 2 feet:
def main():
getInput()
def getInput():
h = int(input("Enter the initial height of the ball: ")) # Adding the int keyword before input() function
v = int(input("Enter the initial velocity of the ball: ")) # Same as above
isValid(h,v)
def isValid(h,v):
if ((h <= 0) or (v <= 0)):
print("Please enter positive values")
getInput()
else:
maxHeight(h,v)
def maxHeight(h,v):
t = (v/32)
maxH = (h + (v*h) - (16*t*t))
print ("\nMax Height of the Ball is: " + str(maxH) + " feet")
ballTime(h, v)
def ballTime(h,v):
t = 0
ballHeight = (h + (v*t) - (16*t*t))
while (ballHeight >= 0):
t += 0.1
ballHeight = (h + (v*t) - (16*t*t))
print ("\nThe ball will hit the ground approximately after " + str(t) + " seconds")
# Driver Code
main()
Answer:
I am writing a python code.
def getInput():
h = int(input("enter the height: "))
v = int(input("enter the velocity: "))
isValid(h,v)
def isValid(h,v):
if (h<= 0 or v<=0):
print("not positive ")
else:
height = maximumHeight(h,v)
print("maximum height of the ball is", height," ft.")
balltime = ground_time(h,v)
print("The ball will hit the ground after", balltime, "s approximately.")
def maximumHeight(h,v):
t = (v/32)
maxheight = (h + (v*t) - (16*t*t))
return maxheight
def ground_time(h,v):
t = 0.1
while(True):
heightofball = (h + (v*t) - (16*t*t))
if (heightofball <= 0):
break
else:
t += 0.1
return t
Explanation:
There are four functions in this program.
getInput() function is used to take input from the user which is height and velocity. h holds the value of height and v holds the value of velocity. input() function is used to accept values from the user.
isValid() function is called after the user enters the value of height and velocity. This function first checks if the value of height and velocity is less than 0. If it is true the message not positive is displayed. If its false then maximumHeight() is called which returns the maximum height of the ball and function ground_time() is called to return the time when the ball will hit the ground.
maximumHeight() function first divides the value of velocity with 32 as the ball will reach its maximum height after v/32 seconds. It then returns the maximum height by using the formula: heightofball = (h + (v*t) - (16*t*t)).
ground_time() calculates the time the ball takes to reach the ground. There is a while loop to height after every 0.1 second and determine when the height is no longer a positive. It uses (h + (v*t) - (16*t*t)) formula to calculate the height and when the value of height gets less than or equal to 0 the loop terminates otherwise it keeps calculating the height while adding 1 to the value of t at each iteration. After the loop breaks, it returns the value of t.
To see the output of the maximum height and time taken by ball to reach the ground, you can call the getInput() function at the end of the above program as:
getInput()
Output:
enter the height: 9
enter the velocity: 10
maximum height of the ball is 10.6525 ft.
the ball will hit the ground after 1.2 s approximately.