Learn Geek languages like Big data,Hadoop,Hive,Pig,Sqoop ,flume,Cassandra,Hbase,Ruby On Rails,Python,Java and many more.

Friday 24 June 2016

#methods with arguments

def ask(question,answer)
   
      i = 0
puts question
         ans=gets.chomp.to_i
      if ans==answer
             @true+=1
            puts "correct"
       else
             puts "wrong answer"
        end
 

 end
question=['what is 8+6','5*4?','7-4?','3*5','9/3']
answer=[14,20,3,15,3]
@true=0
for i in 0..4
ask(question[i],answer[i])
end
puts "true answer : #@true"


OUTPUT:

what is 8+6
3
wrong answer
5*4?
20
correct
7-4?
3
correct
3*5
15
correct
9/3
3
correct
true answer : 4



#random addition

def random_addition

@arg1=rand(-2..0)
@arg2=rand(98..100)

puts "Random addition of two numbers :"
puts "What is #@arg1 + #@arg2 ?"

@arg3 =@arg1.to_i + Integer(@arg2)
puts "#@arg3"

end

random_addition

OUTPUT:

Random addition of two numbers :
What is 0 + 100 ?
100


program for ruby:

#method#

def addition

@arg1=gets.chomp
@arg2=gets.chomp

puts "addition of two numbers :"
puts "What is  @arg1 + @arg2 ? "

@arg3 =@arg1.to_i - @arg2.to_i
puts "#@arg3"

end
puts "enter 2 nos"
addition

OUTPUT
enter 2 nos
23
3
addition of two numbers :
What is  @arg1 + @arg2 ?
20

Monday 13 June 2016


1. ctrl+alt+t = To open terminal.
2. ctrl+shift+ = To large the terminal.
3. pwd = This command is use to know the present working directory.
4. cd             = To change working directory as "cd Desktop".
5. ls              = To show the content of any directory/file as a list.
6. clear          = To clear the terminal.
7. gcc "filename" = To compile a file.
8. sudo          = Mean "super user do" if any command is not working than use sudo to make it                                       work.
9. su              = Means "switch user" to switch user.
10.cal = To see calender.
11.date         = To see date.
12.ls -a = To show hidden file.
13.man "command" = To get help for any command.
14.who = Who opens the terminal.
15.whoami = To know which user is working.


TO CREATE OR DELETE ANY DIRECTORY OR FILE.

1.mkdir "filenames" = To create a diectory.
2.rmdir "filenames"         = To remove an existing directory.
3.rm -rf "filename"         = If a folder contain many files than to remove a particular file freom the folder.
4.touch "file name"         = To create files with different extensions in a single command.
5.gedit "file name"          = The file is open in terminal and no command will work in terminal..
6.pkill "process name" = To close a process in background.
7.kill "process id"           = To kill a process if process id is known.
8.ls "file name"               = To check either the file is present or not.

9.cat "filename"            = This command is use to show data of a file on terminal.
10.cat > "filename"         = To enter data in existing file.but previous data will be deleted.
11.cat >> "filename" = To enter data in an existing file in append mode.
12.sudo apt-get install vlc = To install something from net.
13.sudo apt-get update = To check updates from net.

14.wc "filename"            = To see how many lines  words  charcter in a file.
15.cp "source" "des" = To copy a file from one place to another.
16.mv "existing" "new" = name of file will get copied from new to existing.
17.ls -l                           = To see permission of all files.
18.head "filename"         = To read first 10 lines of file.
19.tail "filenmae"           = To read last 10 lines of file.
20.more "filename" = to read a file.
21.less "filenmae"          = to read a file.
22.compress file             =  tar cvzf "file.tar.bz" "file"
23.extract file                 = tar xvzf file.tar.bz