Posted in Tech

A quick guide on the basics of Python

Most people who wish to learn a programming language often cannot find the time or lack the facilities or opportunities. For the past eight years or so, I’ve had such difficulties that obstructed me from mastering one. It wasn’t until last month that I could actually learn python and I figured that I could post some of the things that I learned in the form of a guide.

Before we start, know that a string is line of characters. example – “Hello”

So the first thing one must learn to do when learning a programming language is how to display text using python, i.e. we use the print() method

syntax 
1 print("hello world")
2 print(23)  <-- the 23 if put like this ->("23") becomes a *string
3 print(2 + 3) 
4 print("2"+"3")<--(these nos. are nos. strings(gets *concatenated) 

output
1 Hello World
2 23 

You can assign word(s) or variables . They are called to display a certain string or integer etc.

syntax
1 text = " Hello World"
  print(text)
2 text = print("Hello World")

output
1 Hello World
2 Hello World

String concatenation is useful when you want to merge different strings together.

syntax
1 fruit = "Apples"
  statement = " are nice!"
  print (fruit + statement)

output
1 Apples are nice!

You can also put items in a list and pull out and add more as you go.

Here you have an empty list:

syntax
1 books = []

To add items to the list we use the .append method :

syntax
1 books = []
  books.append("Harry Potter")
  books.append("Wimpy Kid")
  print(books)

output
1 ["Harry Potter" , "Wimpy Kid"]

Another thing to keep in mind is that in a string or list for example ,every piece (word or no. etc) has it’s own index or position no. For example, in “Wimpy Kid” Both “Wimpy” and “Kid” have their own index no. Also remember that the count starts from 0 and not from 1 therefore “Wimpy” has the index no. 0 and so on. this can be applicable to just one word where index positions are alloted to specific characters and even in numericals. the index no. is given in this –> []

syntax
1 text = "Hello World"
  print(text[1])
2 word = "littlebanyantreekids"
  print(word[6])
3 number = 79936429
  print(number[4])
4 sentence = "You are awesome"
  print(sentence[-1])
  print(sentence[-2] 

output
1 Hello
2 b
3 6
4 awesome
  are

Index position [-1] is possible and is the last word character or numerical in the string or integer.

You can use index positions to get data from a list as well:

syntax 
1 mylist = ["books","games","movies","programming"]   print(mylist[3]) 

output
1 programming

You can also pick up more than one item by adding a stop index to the start one , [0:2]. The first no. indicates which index position to begin from and the second indicated where it should stop. note, that the no. in the stop index is not counted therefore goes only up to but but excudes it therefore in this case only only index[0] and index[1] are taken and not index[2].

input
1 names = ['Sam', 'Bob', 'Adam', 'Alice'] 
  print(names[:2])

output
1 ["Sam" , "Bob"]
  

When assigning a new list by picking entries from another list it is called slicing:

syntax
input
1 names = ['Sam', 'Bob', 'Adam', 'Alice'] 
 siblings = names[:2]

output
1 ["Sam" , "Bob"]

Here’s an example of how we can manipulate and play with numbers using lists

syntax
1 squares = [] 
  for number in range(1, 11): 
     squares.append(number**2)  <-------(indent is important)
  print(squares)

output
[1,4,9,16,25,36,49,64,81,100,121]

What the code above implies is that : 1. squares is an empty list . For every number from a range of 1 to 11, square the number and append it to squares (the list).

List comprehensions are a shorter way but not necessarily most readable ways to create lists the objective if used is to minimise the space taken up by code:

syntax
1 squares = [number**2 for number in range(1, 11)]  
  print(squares)

output
[1,4,9,16,25,36,49,64,81,100,121]

And that is all that we have for this months edition. More from me next month. I hope you found this useful . 🙂

Advertisement
Posted in Tech

AOC Agon AG352UCG gaming monitor

Screen Shot 2018-07-06 at 11.37.44 AM
photo credit: kevin @ amazon reviews

If you call yourself an avid gamer, then AOC Agon AG352UCG is a gaming monitor that you are sure to fall in love with. At $799.99, the amazon prize for  AOC Agon AG352UCG is worth buying only because it is packed with an amazing lot of features.

Here are 6 reasons to buy –

  1. It is a great cheaper alternative to other monitor options in the little above mid- range group, say a Acer predator X34.
  2. A 35inch monitor enhances the gaming experience to humongous degrees. It allows you to see opponents on the sides more quickly.
  3. The curved screen keeps you glued in the game turning you into the coolest zombie ever.
  4. It has all the basic input ports – an HDMI slot, a display port, four USB ports
  5. Great for movie watching with friends on any weekend.
  6. Go for the looks! It’s crazy beautiful!

If you have a ‘cool dad’ who absolutely thinks like you, now would be a great time to start working up a deal with him. Other cool things are easy installation ( just a few screws and a stand) and a little pull out to hang the headphones.

Well you need that special nook and you need a desk that can take the monster monitor. If you do, I  honestly think this one is for you.


Soham

Posted in Tech

Easy life with Alexa !

Alexa is a controlled and a wireless echo speaker. At this moment it is in its second generation. It has many different versions of it available. It continues to expand its music, smart home, and digital assistant. With the help of the sound of your voice, you can play music, search the web, create to-do and shopping lists, shop online, get instant weather reports, and control popular smart-home products.

Without touching anything, you can walk into a quiet room and ask for music, or walk into a dark room and ask for lights.

Amazon built a natural-language processing system that is one of the easiest to interact with we’ve seen. If you ask a question a command, you usually don’t have to ask twice.

As noted earlier, Echo devices stream your voice to the cloud only when you ask it to do something .The default wake word is “Alexa,” but you can change that to “Echo,” “Amazon,” or “Computer.”

Once you say the magic word, the microphone takes everything you say next and beams it up to Amazon’s cloud computers for quick analysis. If it’s a question it can answer, such as, “Alexa, what’s the weather in Chicago today?” and answer comes forth from the speaker in a female, slightly ‘computery’ voice. If it’s music you want, Alexa will search through the Amazon Music catalog or Amazon Prime Music for the artist or genre you requested.

Alexa can do a lot of things, but sometimes in practice, things might not work exactly how you would expect them to. For example, you can create a shopping list by telling Alexa to add firecrackers or beer to your list, but you must add each item separately. That is, instead of saying “Alexa, add firecrackers and beer to my shopping list,”you have to say “Alexa, add firecrackers to my shopping list. Alexa, add beer to my shopping list.” The process can get annoying if you’re creating a large shopping list, especially for other people in the room. Further, though Alexa nicely creates a shopping list in its app (that you can access when you’re in the grocery store), you need to use an IFTTT recipe to create a version of the list for sharing or0 printing.

In short, Alexa is a very good device!