Answer:
1. Using meaningful names for all variables and functions.
2. Use shorter blocks of codes wherever possible
Explanation:
Their code should be easy to read, this can be achieved by avoiding complex syntax, basically they should adopt the two methods stated in the answer
Answer:
see explaination
Explanation:
class Taxicab():
def __init__(self, x, y):
self.x_coordinate = x
self.y_coordinate = y
self.odometer = 0
def get_x_coord(self):
return self.x_coordinate
def get_y_coord(self):
return self.y_coordinate
def get_odometer(self):
return self.odometer
def move_x(self, distance):
self.x_coordinate += distance
# add the absolute distance to odometer
self.odometer += abs(distance)
def move_y(self, distance):
self.y_coordinate += distance
# add the absolute distance to odometer
self.odometer += abs(distance)
cab = Taxicab(5,-8)
cab.move_x(3)
cab.move_y(-4)
cab.move_x(-1)
print(cab.odometer) # will print 8 3+4+1 = 8
Answer:
This program is executed in Dev C++ using C++ as a programming language.
Explanation:
#include<iostream>
using namespace std;
int main()
{
int carModelNo;
cout<<"Enter Car Model Number ";
cin>>carModelNo;
EnterAgain:
if(carModelNo==1969)
{
cout<<"Few safety features.";
}
else if(carModelNo==1979)
{
cout<<"Probably has seat belts.";
}
else if(carModelNo==1999)
{
cout<<"Probably has antilock brakes.";
}
else if(carModelNo==2000)
{
cout<<"Probably has airbags.";
}
else
{
"Car Model Information Currently not Available";
cout<<"Please enter the car model such as 1969, 1979, 1999, or 2000 ";
cin>>carModelNo;
goto EnterAgain;
}
return 0;
}
Answer:
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
double caffeineMg;
cin>>caffeineMg;
cout<<"After 6 hours: "<<fixed<<setprecision(2)<<caffeineMg/2.0<<" mg\n";
cout<<"After 12 hours: "<<fixed<<setprecision(2)<<caffeineMg/4.0<<" mg\n";
cout<<"After 24 hours: "<<fixed<<setprecision(2)<<caffeineMg/8.0<<" mg\n";
return 0;
}
Explanation:
- Declare a variable for caffeine and take the input from user.
- Print the results by dividing the caffeine by relevant Half Life.
- Use setprecision function to display the result up to 2 decimal places.