Hello Worlds and Simple Program

I did this exercise with:
HP Pavilion 15-aw022no
AMD A9-9410 (2.9GHz, 2 Cores)
8GB DDR4-SDRAM 2133MHz (2 x 4)256GB SSD
AMD Radeon R7 M440 (2GB, GDDR3)
Ubuntu 16.04 (Live USB)
Instructions for exercises from: http://terokarvinen.com/2017/aikataulu

1. Write and run “Hello World” with three different languages. Install needed environments.

a) Python

hellopython1First I created a text file helloworld.py to Desktop. Into the file I typed #!/usr/bin/python and then print ‘Hello World’. Then I gave permission to run it with command chmod +x ~/Desktop/helloworld.py. And finally ran the program with command python helloworld.py.

Python3 is a working environment for python coding. Install it with command sudo apt-get install python3. Run it with command python3 and then just type print(‘Hello world!’) and hit enter.


b) PHP

First I installed PHP7.1 with command sudo apt-get install php7.1. Then I created a text file called helloworld.php with command nano ~/Desktop/helloworld.php. File contents in image below. Finally I ran the program with command php helloworld.php.


c) C

I installed gcc, a compiler for C language sudo apt-get install gcc. Then I created a text file nano ~/Desktop/helloworld.c, which contents are in image below. I moved to Desktop folder with command cd ~/Desktop. Then I compiled it with command gcc helloworld.c -o helloworld. Lastly I ran the program with command ./helloworld.


2. Create a simple program with these languages

With these instructions I managed to succesfully retrieve a rss sport news feed from mtv.

Instructions: https://www.youtube.com/watch?v=4ZLZkdiKGE0


SimpleXML extension of PHP must be installed!

Source code:

$html = “”;
$url = “https://www.mtv.fi/api/feed/rss/urheilu”;
$xml = simplexml_load_file($url);

for($i = 0; $i < 20; $i++){
$title = $xml->channel->item[$i]->title;
$link = $xml->channel->item[$i]->link;
$description = $xml->channel->item[$i]->description;
$pubDate = $xml->channel->item[$i]->pubDate;
$category = $xml->channel->item[$i]->category;

$html .= “<a href=’$link’><h3>$title</h3></a>”;
$html .= “$description”;
$html .= “$enclosure”;
$html .= “<br /><p></p>$category</p> $pubDate<hr />”;
echo $html;

(Edit 9.4.2018 Added notification of XML-extension and source link.)



Leave a Reply

Your email address will not be published.