Welcome to namasudra.blogspot.com. Glad to see you here!
Showing posts with label Misc. Show all posts

Wednesday, March 13, 2019

Kawaljit Singh asked:

Explain the code along with output

adict={'Bhavna':1,'Richad':2,'Firoza':10,'Arshnoor':20}
temp = ""
for key in adict:
    if temp<key:
        temp=key
print(temp)


To understand this in a better way, please write the following code and inspect what happens to the variables in each pass of the for loop.

adict={'Bhavna':1,'Richad':2,'Firoza':10,'Arshnoor':20}
temp = ""
for key in adict:
    print("key =", key, "and temp =", temp)
    print("so", temp, "<", key, "is", temp<key)
    if temp<key:
        temp=key
        print("so temp =", key)
    print("--------next pass--------")
print(temp)


Hope this helps.

Sunday, February 10, 2019

Summer Vaccation Homework (Q9)

Q. Write a program that creates a list of all the integers less than 100 that are multiples of 3 or 5.

Code:


Summer Vaccation Homework (Q8)

Q. Write a program that takes any two lists L and M of the same size and adds their elements together to form a new list N whose elements are the sums of their corresponding elements in L and M. (for instance if L = [3, 1, 4] and M = [1, 5, 9], then N should be equal to [4, 6, 13])

Code:


Saturday, February 9, 2019

Code for Sheeba

Sheeba's Question:

I'm trying to form a dictionary that has the key as the first name and values as the list of the last names given in the list of lists. I've attached a screenshot of my problem. The input list is from line number 9 to line number 11. The required answer is from line number 21 to line number 23. I first split the names in the given list of lists into first and last names. Formed a dictionary with a list and appended the last names to it. I'm not able to attach al the last names to the list of values. My answer is on the right side of the screenshot. Please help me with this.


Solution:

source = [["David Joyner","David Tennant","David Beckham"],
          ["Ananya Birla","Ananya Agarwal","Ananya Chatterjee","Ananya Roy"],
          ["Ines Sainz","Ines Suarez","Ines Melchor"]]

def extract_names(a_list):
    dict = {}
    for lst in a_list:
        values_list = []
        name_part = lst[0].split()
        key = name_part[0]
        for name in lst:
            name_part = name.split()
            values_list.append(name_part[1])
        dict[key] = values_list
    return dict

ans = extract_names(source)
print(ans)

Thursday, June 2, 2016

Manually creating a bootable USB drive for Windows 7

To create a bootable USB drive we will be needing a pen-drive of 4GB minimum capacity. We will be using the Command Prompt to type in our commands.

Step 1: Creating Partition

Please follow the following steps to create the partition.
  • Insert the pen-drive into your computer and note down the drive letter. For this example we assume that the drive letter is E: for the USB pen-drive.
  • Also note down the drive letter of your DVD drive. We assume the drive letter is D: for the DVD drive.
  • Now, run the Command Prompt as Administrator. To do this, we need to type cmd in the Search Box on Windows Start Menu. When cmd appears, right click on it and select "Run as administrator".
  • Command Prompt should open at "C:\Windows\system32>" by default. Type diskpart and press Enter. The diskpart program will run, wait until you see "DISKPART>" prompt.
  • After the DISKPART> prompt appears, type in list disk and press Enter. This will show you the installed disks on your computer. Identify your USB drive by its size. It would show something like, Disk 0 for your hard disk and Disk 1 for your USB pen-drive.
  • Type select disk 1 and press Enter (assuming Disk 1 is your USB drive).
  • Now, type clean and press Enter to delete all the data on your USB pen-drive.
  • Type create partition primary and press Enter. This will create a partition as partition 1.
  • Type select partition 1 and press Enter to select the partition.
  • Type active and press Enter to make the partition as the active partition.
  • Type format fs=ntfs quick and press Enter. This will format the active partition in NTFS format.
  • Type exit and press Enter to close the DISKPART program.
We are done with creating partition. Next, we need to create a boot sector to make the USB drive bootable.

Step 2: Making the USB drive bootable

In the previous step we have assumed the following drive letters,
E: for USB pen-drive
D: for DVD drive
In the Command Prompt window, we are presently in the location C:\Windows\System32> by default.
  • We will change the drive to DVD by typing D: and press Enter.
  • Type cd boot and press Enter to change the directory to D:\boot>.
  • Type bootsect /nt60 E: and press Enter. This will create the boot sector on our USB drive(E:).
  • Type exit and press Enter to close the Command Prompt.
Our USB pen-drive is now ready to be used as a bootable pen-drive. We just need copy the Windows installation files on the DVD to the USB drive.

Step 3: Copying Installation Files

Open Command Prompt again as Administrator like before. Now, type the following

xcopy D:\*.* E:\ /E /H /F

That's it. It will take a while to copy the installation files from DVD to USB drive. After the copy process is complete, the USB pen-drive would be ready to be used for installing Windows.