1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
ser-zykov [4K]
3 years ago
14

Python 3 (not java)1.Assume that word is a variable of type String that has been assigned a value. Write an expression whose val

ue is a String consisting of the last three characters of the value of word. So if the value of word were "biggest" the expression's value would be "est".2.Given three String variables that have been given values, firstName, middleName, and lastName, write an expression whose value is the initials of the three names: the first letter of each, joined together. So if firstName, middleName, and lastName, had the values "John", "Fitzgerald", and "Kennedy", the expression's value would be JFK". Alternatively, if firstName, middleName, and lastName, had the values "Franklin", "Delano", and "Roosevelt", the expression's value would be "FDR".3.Write an expression that evaluates to True if and only if the variables profits and losses are exactly equal.
Computers and Technology
1 answer:
zhenek [66]3 years ago
8 0

Answer:

#part 1.

#declare and initialize string variable word

word="welcome"

# extract the last 3 characters of the string and print

print("last 3 characters of word is: ",word[-3:])

#part 2.

#declare and initialize string variables

firstName="John"

middleName="Fitzgerald"

lastName="Kennedy"

#print the initials of all names

print("initials of name is: ",firstName[0]+middleName[0]+lastName[0])

#part 3.

#declare and initialize profit and loss

profits=10

losses=10

# if will be true only when profits equals to losses

if profits==losses:

   print("both are equal")

Explanation:

In part 1, declare and initialize string variable word with "welcome" then extract last 3 characters of the string and print it. In part 2, declare and initialize names variable then find the first character of each name that is character at 0 index. Append all 3 and print that value. In part 3, declare and initialize profits with 10 and losses with 10. In the if condition, it will print  "both are equal" if both values are equal.

Output:

last 3 characters of word is:  ome                                                                                            

initials of name is:  JFK                                                                                                    

both are equal

You might be interested in
def getCharacterForward(char, key): """ Given a character char, and an integer key, the function shifts char forward `key` steps
zhenek [66]

Answer:

  1. def getCharacterForward(char, key):  
  2.    charList = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
  3.    if(len(char) > 1):
  4.        return None  
  5.    elif(not isinstance(key, int)):
  6.        return -1
  7.    else:
  8.        index = charList.find(char)
  9.        if(index + key <= 25):
  10.            return charList[index + key]
  11.        else:
  12.            return charList[(index + key)% 26]
  13. print(getCharacterForward("C", 4))
  14. print(getCharacterForward("X", 4))

Explanation:

Firstly, define a charList that includes all uppercase alphabets (Line 2). We presume this program will only handle uppercase characters.

Follow the question requirement and define necessary input validation such as checking if the char is a single character (Line 4). We can do the validation by checking if the length of the char is more than 1, if so, this is not a single character and should return None (Line 5). Next, validate the key by using isinstance function to see if this is an integer. If this is not an integer return -1 (Line 6 - 7).

Otherwise, the program will proceed to find the index of char in the charList using find method (Line 9). Next, we can add the key to index and use the result value to get forwarded character from the charList and return it as output (Line 11).

However, we need to deal a situation that the char is found at close end of the charList and the forward key steps will be out of range of alphabet list. For example the char is X and the key is 4, the four steps forward will result in out of range error. To handle this situation, we can move the last two forward steps from the starting point of the charList. So X move forward 4 will become B. We can implement this logic by having index + key modulus by 26 (Line 13).  

We can test the function will passing two sample set of arguments (Line 15 - 16) and we shall get the output as follows:

G

B

8 0
3 years ago
Which microsoft operating system started the process of authenticating users with a user name and password?
11111nata11111 [884]
It should be either windows 98 or windows xp but I think it is windows xp
5 0
3 years ago
Setting your __________ will prevent you from having to type your name in every email.
Kay [80]

I believe its D. Signature.

7 0
3 years ago
Read 2 more answers
Your solution should for this assignment should consist of five (5)files:============================================== FuelGaug
olga nikolaevna [1]

Answer: provided in the explanation section

Explanation:

This was implemented in C++

Filename: Car.cpp

#include <iostream>

#include <iomanip>

#include <cstdlib>

#include "Odometer.h"

using namespace std;

int main()

{

  char response;

  do

  {

      FuelGuage* myFuel = new FuelGuage(6);

      int fuelLevel = myFuel->getFuel();

      cout << "Car gas level: " << fuelLevel << endl;

      cout << "Car is filling up" << endl;

      while(myFuel->getFuel() < 15)

      {

          myFuel->addFuel();

      }

      Odometer* car = new Odometer(myFuel, 999990);

      cout << "Car gas level: " << car->getFuelGuage()->getFuel() << endl;

      cout << "Car is off!" << endl;

      cout << "--------------------------" << endl;

      while(car->getFuelGuage()->getFuel() > 0)

      {

          car->addMile();

          int miles = car->getMileage();

          cout << "Mileage: " << setw(6) << miles << ", Fuel Level: " << car->getFuelGuage()->getFuel() << endl;

          cout<<"--------------------------------------------------------------"<<endl;

      }

      delete myFuel;

      delete car;

      cout << "Would you like to run the car again(Y/N)? ";

      cin >> response;

      system("cls||clear");

  } while(toupper(response) != 'N');

  return 0;

}

Filename: FuelGuage.cpp

#include "FuelGuage.h"

FuelGuage::FuelGuage()

{

  init();

}

FuelGuage::FuelGuage(int fuel)

{

  init();

  this->fuel = fuel;

}

FuelGuage::FuelGuage(const FuelGuage& copy)

{

  this->fuel = copy.fuel;

}

void FuelGuage::init()

{

  this->fuel = 0;

}

int FuelGuage::getFuel()

{

  return fuel;

}

void FuelGuage::addFuel()

{

  fuel++;

}

void FuelGuage::burnFuel()

{

  fuel--;

}

Filename:FuelGuage.h

#ifndef FUEL_GUAGE_H

#define FUEL_GUAGE_H

class FuelGuage

{

private:

  int fuel;

  void init();

public:

  FuelGuage();

  FuelGuage(int fuel);

  FuelGuage(const FuelGuage& copy);

  int getFuel();

  void addFuel();

  void burnFuel();

};

#endif

Filename : Odometer.cpp

#include "Odometer.h"

Odometer::Odometer()

{

  init();

}

Odometer::Odometer(FuelGuage* inFuel, int inMileage)

{

  init();

  this->fuel = new FuelGuage(*inFuel);

  this->mileage = inMileage;

  this->milesSinceAddingFuel = 0;

}

void Odometer::init()

{

  fuel = new FuelGuage();

  mileage = 0;

  milesSinceAddingFuel = 0;

}

FuelGuage* Odometer::getFuelGuage()

{

  return fuel;

}

int Odometer::getMileage()

{

  return mileage;

}

void Odometer::addMile()

{

  if(mileage < 999999)

  {

      mileage++;

      milesSinceAddingFuel++;

  }

  else

  {

      mileage = 0;

      milesSinceAddingFuel++;

  }

  if((milesSinceAddingFuel % 24) == 0)

  {

      fuel->burnFuel();

  }

}

void Odometer::resetMiles()

{

  milesSinceAddingFuel = 0;

}

Odometer::~Odometer()

{

  delete fuel;

}

Filename: Odometer.h

#ifndef ODOMETER_H

#define ODOMETER_H

#include "FuelGuage.h"

class Odometer

{

private:

  void init();

  int mileage;

  int milesSinceAddingFuel;

  FuelGuage* fuel;

public:

  Odometer();

  Odometer(FuelGuage* inFuel, int inMileage);

  FuelGuage* getFuelGuage();

  int getMileage();

  void addMile();

  void resetMiles();

  ~Odometer();

};

#endif

6 0
2 years ago
Which function can be used to insert the current date into a spreadsheet?
VladimirAG [237]

Answer:

im pretty sure it MM/DD/YYYY

Explanation:

3 0
3 years ago
Other questions:
  • An excel file called “student_gpa” is opened. What does the funnel next to “GPA” indicate
    5·1 answer
  • How does consumption of alcohol affect your driving skills? Name three ways that alcohol can affect your driving.
    15·2 answers
  • A network administrator is using packet tracer to mock up a network that includes iot devices. What can the administrator do fro
    15·1 answer
  • Write a function to output an array of ints on a single line. Funtion Should take an array and an array length and return a void
    9·1 answer
  • If you use the assign software to a user option, how does the new software install to the user's computer? 70-411
    10·1 answer
  • The user does not need to highlight data within an Excel worksheet in order to remove conditional formatting. True or false
    14·1 answer
  • What is it called when an attacker convinces you to enter personal information at an imposter website after receiving an email f
    10·2 answers
  • Name at least TWO kinds of gaming experiences that are possible with these new control devices but were not possible on original
    7·1 answer
  • Look at the following structure declaration.
    6·1 answer
  • 4.2 lesson practice help plzs
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!