Ask Question
23 December, 11:03

Given two variables firstInClass and secondInClass which have already been associated with values, write code which swaps the values to which they are associated. For example, if firstInClass starts with the value "Pat", and secondInClass starts with the value "Wei", firstInClass should wind up associated with "Wei" and secondInClass should wind up associated with "Pat". Note: you should NOT assign values to firstInClass and secondInClass.

+2
Answers (1)
  1. 23 December, 14:46
    0
    Following are the code in the python language

    if firstInClass. startswith ("Pat") and secondInClass. startswith ("Wei") : #check the #condition

    firstInClass, secondInClass = secondInClass, firstInClass #swap value

    Explanation:

    Following are the description of statement

    Firstly we check the condition the string start with pat with the string start with the Wei string along with the and operator with them. If the condition is true then it executed the block of if statement means executed the statement inside the if block. It means it swap the statement without assigning the value.
Know the Answer?
Not Sure About the Answer?
Find an answer to your question ✅ “Given two variables firstInClass and secondInClass which have already been associated with values, write code which swaps the values to ...” in 📘 Computers and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers